I want to compare plaintext password to crypted_password and salt saved in database for that I have function named passwordisvalid() which has3 parameters (string,byte[],byte[]) string for plaintextpassword,byte[] for saved cryptedpassword and saved salt and crypted_password and salt attributes are of varchar type are in database so my question is how can I convert varchar datatype to byte[] so that I can pass it to passwordisvalid()?
public static bool IsPasswordValid(string passwordPlainText, byte[] savedSaltBytes, byte[] savedHashBytes)
{
byte[] array1 =GenerateSaltedHash(passwordPlainText,savedSaltBytes);
byte[] array2 = savedHashBytes;
if (array1.Length != array2.Length)
return false;
for (int i = 0; i < array1.Length; i++)
{
if (array1[i] != array2[i])
return false;
}
return true;
}
Any help will be appreciated.