ASP.NET Membership change password not working

前端 未结 10 1875
心在旅途
心在旅途 2021-02-19 18:48

I have this code for changing a user\'s password when they click the password reset button (with extra code to log to ELMAH so I can try to figure out what is going wrong).

10条回答
  •  半阙折子戏
    2021-02-19 19:34

    Well this is certainly an interesting one. The "it works for some, not for others" part is really bizarre.

    Is this an intermittent problem, or does it always occur for certain users, and always not occur for other users?

    One of the other people here suggested running ValidateUser(username, newPassword) to confirm that the user could properly authenticate before assuming success.

    Have you tried this? You could continuously loop, resetting + changing the password until ValidateUser is successful, perhaps exiting after N failures.

    bool success = false;
    int numAttempts = 0;
    do
    {
        string pwd = user.ResetPassword();
        if (user.ChangePassword(pwd, confirmPassword))
        {
            success = Membership.ValidateUser(user.UserName, pwd);
        }
        numAttempts++;
    } while(numAttempts < 5 && !success);
    

    Note: This is not for use in production, just for testing to see if this resolves the problem.

提交回复
热议问题