ASP.NET 会员在不知道旧密码的情况下更改密码
评估方法签名时,更改密码时需要知道旧密码。
membershipUser.ChangePassword(userWrapper.OldPassword, userWrapper.Password)
有没有办法在不知道旧密码的情况下更改密码。
Evaluting the method signature, it is required to know old password while changing it.
membershipUser.ChangePassword(userWrapper.OldPassword, userWrapper.Password)
Is there any way to change password without knowing old one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
这里的其他答案是正确的,但可能会使密码处于未知状态。
如果密码不满足 Web.Config 中规定的要求(最小长度等),
ChangePassword
将引发异常。但只有在调用ResetPassword
后它才会失败,因此原始用户或尝试更改密码的人不会知道密码。在更改密码之前检查复杂性要求以避免出现这种情况:The other answers here are correct, but can leave the password in an unknown state.
ChangePassword
will throw exceptions if the password doesn't meet the requirements laid out in Web.Config (minimum length, etc.). But it only fails afterResetPassword
has been called, so the password will not be known to the original user or to the person who's tried to change it. Check for complexity requirements before changing the password to avoid this:更改用户密码之前需要重置用户密码,并将生成的密码传入
ChangePassword
。或内联:
You need to reset the user's password before changing it, and pass in the generated password to
ChangePassword
.or inline:
尝试使用 SimpleMembershipProvider 它更容易:
Try to use SimpleMembershipProvider it's easier:
请注意,只有在会员系统配置中将
RequiresQuestionAndAnswer
属性设置为 false 时,所有这些提到的解决方案才会起作用。如果 RequiresQuestionAndAnswer 为 true,则 ResetPassword 方法需要传递安全答案,否则将引发异常。如果您需要将 RequiresQuestionAndAnswer 设置为 true,您可以使用此 解决方法
Please note, all these mentioned solutions will only work if the
RequiresQuestionAndAnswer
property is set to false in Membership system configuration. IfRequiresQuestionAndAnswer
is true then the ResetPassword method needs to be passed the security answer, otherwise it will throw an exception.In case you need
RequiresQuestionAndAnswer
set to true, you can use this workaround上面帖子中提到的这段代码正在工作:
但是您必须在会员提供程序标记中的 web.config 中设置 requireQuestionAndAnswer="false" 。如果为 true,resetpassword 方法会生成错误“值不能为空”。
在这种情况下,您必须提供问题答案作为 ResetPassword 的参数。
This code mentioned on posts above is working:
But you have to set requiresQuestionAndAnswer="false" in web.config in membership provider tag. If it is true, resetpassword method generate an error "Value can not be null".
In this case you must supply question answer as parameter to ResetPassword.
使用文本框中您要设置的密码代替 123456。
Use the password you want to set from textbox in place of 123456.
@Rob Church 是对的:
但是,我不会尝试使用 ResetPassword from token 方法更改密码,并捕获并显示错误,而不是手动进行验证的解决方案:
@Rob Church is right:
However, instead of his solution to do the validation by hand, I would try to change the password using the ResetPassword from token method and catch and show the error: