Retrieve ASP.NET Membership Security Question
I am implementing a reset password aspx page and in that page, I am doing the following with a Wizard.
- I am asking the user for his/her username, checking to make sure username does exist before moving on.
- In the second view, I want to ask the user to answer his/her security question. I want to display the question and validate what their answer is, and if valid, continue to third step. (At moment,开发者_运维技巧 I'm not sure how to retrieve the security question to display in the second.)
- In third view, ask user to enter in new password.
I understand how to go about changing the password even without the old password, but just can't seem to figure out how to get the security question.
Anyone have any ideas??
Membership.GetUser().PasswordQuestion
contains the Security Question.
Membership.GetUser().ResetPassword(securityQuestionAnswer)
will generate a new random password for the user. You can then email this to the user.
http://msdn.microsoft.com/en-us/library/d90zte4w.aspx
If a password answer is required and an incorrect password answer is supplied, a MembershipPasswordException
is thrown by the membership provider. If you wanted to allow the user to enter a password, you could check to ensure that this exception is not thrown, then change the password.
精彩评论