問題,有沒有一種方法:如果您不知道當前密碼,您如何使用asp.net會員提供程序更改散列密碼?
bool ChangePassword(string newPassword);
你必須知道當前密碼(這可能是散列和遺忘)。
問題,有沒有一種方法:如果您不知道當前密碼,您如何使用asp.net會員提供程序更改散列密碼?
bool ChangePassword(string newPassword);
你必須知道當前密碼(這可能是散列和遺忘)。
這是一個容易的,我浪費了太多時間。希望這篇文章能夠像其他人一樣拼命撫平他們的前額。
解決方案,隨機重置密碼並將其傳遞到更改方法。
MembershipUser u = Membership.GetUser();
u.ChangePassword(u.ResetPassword(), "myAwesomePassword");
您不能更改密碼,如果requiresQuestionAndAnswer =「真」
我得到了解決有關此
創建了兩個成員資格提供在web.config中
我使用AspNetSqlMembershipProviderReset提供程序重置密碼,因爲它具有requiresQuestionAndAnswer = false,其中AspNetSqlMembershipProvider是默認提供程序。
我寫了下面的代碼來重置用戶的密碼。
公共BOOL ResetUserPassword(字符串psUserName,字符串psNewPassword) { 嘗試 { //獲取使用與所需的問題答案設置爲false謝勝利成員提供會員用戶詳細信息。
MembershipUser currentUser = Membership.Providers["AspNetSqlMembershipProviderReset"].GetUser(psUserName,false);
//Reset the user password.
String vsResetPassword = currentUser.ResetPassword();
//Change the User password with the required password
currentUser.ChangePassword(vsResetPassword, psNewPassword);
//Changed the comments to to force the user to change the password on next login attempt
currentUser.Comment = "CHANGEPASS";
//Check if the user is locked out and if yes unlock the user
if (currentUser.IsLockedOut == true)
{
currentUser.UnlockUser();
}
Membership.Providers["AspNetSqlMembershipProviderReset"].UpdateUser(currentUser); return true;
}
catch (Exception ex)
{
throw ex;
return false;
}
}
你應該分開你的問題,並添加一個答案。 – 2008-11-13 16:00:19
@mcqwerty,現在我們已經分開了你的答案,你應該「接受」你自己的回答 – harriyott 2008-11-13 16:01:23