0
我有一个用$ hash = password_hash($ accountpassword,PASSWORD_DEFAULT);登录的主页。 (http://php.net/manual/de/function.password-hash.php)mySQl用c登录#
密码保存为哈希以$ 2y $开头。
然后创建在C#登录:
//crypting the PW that user enter
string cryptedPassword = Crypter.Blowfish.Crypt(textBox_password.Text);
string user = textBox_username.Text;
string pass = cryptedPassword;
if (user == "" || pass == "")
{
MessageBox.Show("Empty Fields Detected ! Please fill up all the fields");
return;
}
bool r = validate_login(user, pass);
if (r)
MessageBox.Show("Correct Login Credentials");
else
MessageBox.Show("Incorrect Login Credentials"+cryptedPassword);
我的验证方法:
private bool validate_login(string user, string pass)
{
db_connection();
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "Select * from users where [email protected] and [email protected]";
cmd.Parameters.AddWithValue("@user", user);
cmd.Parameters.AddWithValue("@pass", pass);
cmd.Connection = connect;
MySqlDataReader login = cmd.ExecuteReader();
if (login.Read())
{
connect.Close();
return true;
}
else
{
connect.Close();
return false;
}
}
在Crypter.Blowfish.Crypt(textBox_password.Text)是拨错。我成为哈希以$ 2a开头$
任何人都可以帮助解决这个问题吗?
嗯php脚本不是我的工作。我怎样才能找出2参数? – Andreas
请使用类似'Crypter.Blowfish.GenerateSalt(6)'的东西,并存储该值,或使用您自己选择的字符串(不太安全)。我已经更新了我的答案,以包含一种替代方法,该方法可以使您无需存储盐即可执行检查。 – Graeme