MembershipUser.ChangePassword fails without warning

别来无恙 提交于 2019-12-23 04:14:14

问题


If I call user.ChangePassword(oldpass,newpass), and the old password is wrong, or the new password does not meet the provider's complexity requirement , the method fails without warning. is there any way i can find out if there is an error and what the error was.

I can always put these checks in my code, but there should be a way to do it using the Membership APIs


回答1:


Unfortunately not. The ChangePassword method only returns a simple bool for success/fail.

Your best option on fail would be to display a generic message to the user stating all possible failure reasons... e.g.

Failed to Change Password.
This may have occured because:

  • The Old Password was incorrect
  • The New Password failed to meet the required complexibility
  • New Passwords must be 8 chars long and contain at least 2 numeric characters. (or whatever)

If you want to give more specific information, then as you said, you would need to implement a rules checker in your own code and relay information to the user based on that check.



来源:https://stackoverflow.com/questions/892256/membershipuser-changepassword-fails-without-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!