【发布时间】:2014-02-17 07:53:22
【问题描述】:
我想将明文密码与保存在数据库中的 crypted_password 和 salt 进行比较,因为我有一个名为 passwordisvalid() 的函数,它有 3 个参数(字符串、字节 []、字节 []) 纯文本密码的字符串,保存的加密密码和保存的盐的字节 [] 和 crypted_password 和 salt 属性是 varchar 类型在数据库中 所以我的问题是如何将 varchar 数据类型转换为 byte[] 以便将其传递给 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;
}
任何帮助将不胜感激。
【问题讨论】:
-
你能分享一些代码吗?
-
public static bool IsPasswordValid(string passwordPlainText, byte[] savedSaltBytes, byte[] savedHashBytes) { byte[] array1 =GenerateSaltedHash(passwordPlainText,savedSaltBytes); byte[] array2 = savedHashBytes; if (array1.Length != array2.Length) 返回 false; for (int i = 0; i
标签: c# type-conversion