如何重置&更改 MVC 中 ASP.NET 成员资格提供程序中的哈希密码
我遇到了代码:
MembershipUser u = Membership.GetUser();
u.ChangePassword(u.ResetPassword(), "Password"); //where will I get the "Password" from
我不明白我将如何 由于用户忘记了旧密码,因此获取客户端密码。 我想添加一个重置功能,它将生成一个随机密码并 向特定客户端发送一封电子邮件,其中包含用户 ID 和随机生成的密码。之后他/她就可以更改密码。
I came accross the code :
MembershipUser u = Membership.GetUser();
u.ChangePassword(u.ResetPassword(), "Password"); //where will I get the "Password" from
I dont understand how I will
get the client password as the user has forgotten his old password.
I want to add a reset functionality which would generate a random password and
send an email to the particular client which will have the userid and the random generated password. After he/she would be able to change the password.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Membership 生成这样的随机密码GeneratePassword 方法
如果您需要创建自己的盐并散列一个新密码,这里是一个与会员代码大致相同的实现:
You can generate a random password like this using the Membership GeneratePassword method
If you need to create your own salt and hash a new password, here is an implementation which does much the same as the membership code:
ChangePassword
方法的第二个参数是一个字符串,代表您要用于该用户的新密码。您可以将其更改为您想要的任何字符串,甚至是您将通过电子邮件发送给用户的自动生成的字符串。
更新
为了回答您的新问题,我相信密码等的所有哈希处理都是由会员提供商处理的。
如果您只是想将用户密码重置为随机新值,则最好使用
ResetPassword
方法而不是ChangePassword
。这将:
The second paremeter of the
ChangePassword
method is a string that reprisents the new password you'd like to use for that user.You can change this to be any string you want, even an auto generated string that you'll email to the user.
UPDATE
To answer your new question, I believe that all hashing of the password etc is handled by the Membership Provider.
If you simply want to reset the users password to a random new value, you might be better using the
ResetPassword
method instead ofChangePassword
.This will: