-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuth.vb
More file actions
44 lines (32 loc) · 1.21 KB
/
Auth.vb
File metadata and controls
44 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Public Enum AuthState
SignedIn
SignedOut
End Enum
Public Class Auth
Property State As AuthState = AuthState.SignedOut
Private Function GetSalt(username As String) As String
Dim ad As New inventoryDataSetTableAdapters.prc_select_saltTableAdapter
Dim dt As New inventoryDataSet.prc_select_saltDataTable
ad.Fill(dt, username)
If dt.Rows.Count = 0 Then
Return ""
End If
Return dt.Rows(0).ItemArray(0)
End Function
Sub SignIn(username As String, password As String)
Dim hashedPassword = Encryption.HashString(password)
Dim salt = GetSalt(username)
Dim hashedAndSaltedPassword = Encryption.HashString($"{hashedPassword}{salt}")
If salt = "" Then
Return
End If
Dim ad As New inventoryDataSetTableAdapters.prc_authenticateTableAdapter
Dim dt As New inventoryDataSet.prc_authenticateDataTable
ad.Fill(dt, username, hashedAndSaltedPassword)
Dim isAuthenticated As Boolean = dt.Rows(0).ItemArray(0)
State = If(isAuthenticated, AuthState.SignedIn, AuthState.SignedOut)
End Sub
Sub SignOut()
State = AuthState.SignedOut
End Sub
End Class