C# MembershipUser.ChangePassword fails for one user only?

大城市里の小女人 提交于 2019-12-08 05:56:55

问题


I'm using the change password feature of the standard AspNetSqlMembershipProvider in my ASP.NET MVC-2 app:

MembershipUser user = Membership.GetUser(userId);
string pwd = user.ResetPassword();
if (user.ChangePassword(pwd, confirmPassword))
{
    // it worked
}

And this works for the vast majority of users, but there are a couple of users that can not change their passwords - user.ChangePassword() just returns false.

I've tried it myself to see what was going on, and entered a simple password 12345678 for that user and it failed to change.

So it's not because they are entering passwords that do not match the password rules. My web.config has the membership provider defined like so:

<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" 
connectionStringName="MembershipDatabaseConnectionString" enablePasswordRetrieval="false" 
enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" 
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="8" 
minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />

Its just the normal definition of AspNetSqlMembershipProvider, there's nothing fancy here.

Why would one user (me) be able to change their password to be 12345678, but another user can not change their password to be 12345678? This other user can not change their password to anything at all.


回答1:


It sounds like those users are locked out.

MembershipUser.ChangePassword calls SqlMembershipProvider.ChangePassword, which returns false if the user is locked out.



来源:https://stackoverflow.com/questions/4001496/c-sharp-membershipuser-changepassword-fails-for-one-user-only

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