Crypto.HashPassword 和 verifyHashedPassword
如标题所示,我使用 MVC 3 helper Crypto 来哈希我的密码,然后除了加密密码之外我什么也不保存到数据库中。
当我实现登录表单时,我创建了一个布尔函数,检索存储在数据库中的密码 并用这个助手得到布尔结果:
Crypto.VerifyHashedPassword(password in DB, password in login form)
if true, then login
if false, the display "password wrong"
这几天,我试图测试我的登录功能。我发现一个事实:如果新的注册商来系统注册,之前的用户将无法登录,显示“密码错误”。
我的程序有问题还是我错过了什么?
Function to return bool
if (Crypto.VerifyHashedPassword(parent.Password, password))
{
return true;
}
else
{
ModelState.AddModelError("", "You was input password wrongly!");
return false;
}
Code to hash and store the password
parent.Password = Crypto.HashPassword(parent.Password);
peoplemanager.Add(parent);
As titled, I'm using MVC 3 helper Crypto to hash my password, then i save nothing except encrypted password into database.
When I implement the login form, I make a boolean function, retrieve password stored in database
and get the boolean result with this helper:
Crypto.VerifyHashedPassword(password in DB, password in login form)
if true, then login
if false, the display "password wrong"
This few day, I was trying to test my login function. I found one fact: If a new registrar comes to register at the system, the previous user will be failed to login, displaying "password wrong".
Is there any problem with my program or did I miss something?
Function to return bool
if (Crypto.VerifyHashedPassword(parent.Password, password))
{
return true;
}
else
{
ModelState.AddModelError("", "You was input password wrongly!");
return false;
}
Code to hash and store the password
parent.Password = Crypto.HashPassword(parent.Password);
peoplemanager.Add(parent);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您遵循本教程,我发现它在创建会员解决方案时非常有帮助:
http://theintegrity.co.uk/2010/12/asp-net-mvc-2-custom-membership-provider-tutorial-part-3/
I would advise you to follow this Tutorial I found it very helpful when creating my membership solution:
http://theintegrity.co.uk/2010/12/asp-net-mvc-2-custom-membership-provider-tutorial-part-3/