I can store the password hashed and with random salt. How can i validate the password?
Public Function GetSaltedHash(pw As String, salt As String) As String
Dim tmp As String = pw & salt
Using hash As HashAlgorithm = New SHA512Managed()
Dim saltyPW = Encoding.UTF8.GetBytes(tmp)
Dim hBytes = hash.ComputeHash(saltyPW)
Return Convert.ToBase64String(hBytes)
End Using
End Function
Public Function CreateNewSalt(size As Integer) As String
Using rng As New RNGCryptoServiceProvider
Dim data(If(size < 7, 7, size)) As Byte
rng.GetBytes(data)
Return Convert.ToBase64String(data)
End Using
End Function
Creating a password with hash and random salt
Const SaltSize As Integer = 31
Dim pw As String = txt_regpass.Text
Dim dbSalt = CreateNewSalt(SaltSize)
GetSaltedHash(pw, dbSalt))