我使用登錄控制和成員asp.net 4.並創建用戶passwrod =「12345678」,我的數據庫中的密碼哈希是「h8A5hga0Cy93JsKxYnJl/U2AluU =」,而passwordsalt是「UhVlqavmEX9CiKcUXkSwCw ==」。什麼是算法哈希與登錄控制?
然後我在其他項目中使用哈希密碼驗證碼:
public string HashPassword(string pass, string salt)
{
byte[] bytes = Encoding.Unicode.GetBytes(pass);
byte[] src = Encoding.Unicode.GetBytes(salt);
byte[] dst = new byte[src.Length + bytes.Length];
Buffer.BlockCopy(src, 0, dst, 0, src.Length);
Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
HashAlgorithm algorithm = HashAlgorithm.Create("SHA1");
byte[] inArray = algorithm.ComputeHash(dst);
return Convert.ToBase64String(inArray);
}
private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = HashPassword("12345678", "UhVlqavmEX9CiKcUXkSwCw==");
}
textBox2.Text = 「YM/JNwFqlL + WA3SINQp48BIxZRI =」。但textBox2.Text!=我的密碼與數據庫中的登錄控制散列在一起。它是「h8A5hga0Cy93JsKxYnJl/U2AluU =」。
編輯:
這是哈希算法與登錄控制?
public string EncodePassword(string pass, string salt)
{
byte[] bytes = Encoding.Unicode.GetBytes(pass);
byte[] src = Convert.FromBase64String(salt);
byte[] dst = new byte[src.Length + bytes.Length];
Buffer.BlockCopy(src, 0, dst, 0, src.Length);
Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
HashAlgorithm algorithm = HashAlgorithm.Create("SHA1");
byte[] inArray = algorithm.ComputeHash(dst);
return Convert.ToBase64String(inArray);
}
是否可以解碼密碼? –
我編輯我的問題。你的代碼是否與我的代碼類似? –