ASP.NET Membership change password not working

前端 未结 10 1871
心在旅途
心在旅途 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:30

    If you are using the built-in SQLServer based providers take a look at your SQL Stored procs. This is what my default proc looks like:

    ALTER PROCEDURE dbo.aspnet_Membership_SetPassword
        @ApplicationName  nvarchar(256),
        @UserName         nvarchar(256),
        @NewPassword      nvarchar(128),
        @PasswordSalt     nvarchar(128),
        @CurrentTimeUtc   datetime,
        @PasswordFormat   int = 0
    AS
    BEGIN
        DECLARE @UserId uniqueidentifier
        SELECT  @UserId = NULL
        SELECT  @UserId = u.UserId
        FROM    dbo.aspnet_Users u, dbo.aspnet_Applications a, dbo.aspnet_Membership m
        WHERE   LoweredUserName = LOWER(@UserName) AND
                u.ApplicationId = a.ApplicationId  AND
                LOWER(@ApplicationName) = a.LoweredApplicationName AND
                u.UserId = m.UserId
    
        IF (@UserId IS NULL)
            RETURN(1)
    
        UPDATE dbo.aspnet_Membership
        SET Password = @NewPassword, PasswordFormat = @PasswordFormat, PasswordSalt = @PasswordSalt,
            LastPasswordChangedDate = @CurrentTimeUtc
        WHERE @UserId = UserId
        RETURN(0)
    END
    

    As you can see the update statement could totally fail and the stored proc could return true. I think this is where your errors are probably coming from. Could be locking issues...

提交回复
热议问题