我使用此代碼哈希然後串店SHA256串DB
static string hashPassword(string password)
{
SHA256Managed crypt = new SHA256Managed();
string hash = String.Empty;
byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(password), 0, Encoding.UTF8.GetByteCount(password));
foreach (byte bit in crypto)
{
hash += bit.ToString("x2");
}
return hash;
}
字符串保存到數據庫到外地「密碼」的數據類型爲nvarchar(最大)進行測試。 問題:
當我運行代碼
string password = hashPassword(maskedTextBox1.Text.ToString());
int valid = this.op_radnikTableAdapter.fLoginData(dimproDataSet.op_radnik,
korisnicko_ime, Convert.ToString(password));
INT有效始終爲0。當我運行在SQL Management Studio或數據集查詢生成器行的查詢將返回:
SELECT TOP 1000 [radnik_id]
,[radnik_aktivan]
,[radnik_dimpro]
,[radnik_ime_prezime]
,[radnik_password]
,[radnik_korisnicko_ime]
,[radnik_isAdmin]
FROM [dimpro].[dbo].[op_radnik]
WHERE (radnik_korisnicko_ime = 'administrator' AND radnik_password = '9af15b336e6a9619928537df30b2e6a2376569fcf9d7e773eccede65606529a0')
密碼是0000 (sha256)
fLoginData
SELECT radnik_id, radnik_aktivan, radnik_ime_prezime, radnik_password, radnik_dimpro, radnik_korisnicko_ime, radnik_isAdmin
FROM op_radnik
WHERE (radnik_korisnicko_ime = @korisnicko_ime) AND (radnik_password = @pass)
感謝
散列代碼看起來不錯,我猜這個問題很簡單,很可能是你傳遞給radnik_korisnicko_ime的值或者fLoginData()中的某個東西 –