简体   繁体   English

更新aspnet会员密码答案

[英]Update aspnet membership password answer

I am going to update security question and answer in aspnet_Membership. 我将在aspnet_Membership中更新安全问题和答案。 Usually it is done by code: 通常它由代码完成:

 user.ChangePasswordQuestionAndAnswer(password, question, answer);

But I don't know the password. 但我不知道密码。 I found that there is a default stored procedure.The stored procedure is: 我发现有一个默认的存储过程。存储过程是:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[aspnet_Membership_ChangePasswordQuestionAndAnswer]
    @ApplicationName       nvarchar(256),
    @UserName              nvarchar(256),
    @NewPasswordQuestion   nvarchar(256),
    @NewPasswordAnswer     nvarchar(128)
AS
BEGIN
   DECLARE @UserId uniqueidentifier
   SELECT  @UserId = NULL
   SELECT  @UserId = u.UserId
   FROM    dbo.aspnet_Membership m, dbo.aspnet_Users u, dbo.aspnet_Applications a
   WHERE   LoweredUserName = LOWER(@UserName) AND
        u.ApplicationId = a.ApplicationId  AND
        LOWER(@ApplicationName) = a.LoweredApplicationName AND
        u.UserId = m.UserId
   IF (@UserId IS NULL)
   BEGIN
      RETURN(1)
   END

   UPDATE dbo.aspnet_Membership
     SET    PasswordQuestion = @NewPasswordQuestion, PasswordAnswer = @NewPasswordAnswer
    WHERE  UserId=@UserId
   RETURN(0)
   END

However I just found the answer is a clear text. 但是我刚才发现答案是明确的。 How can I use the stored procedure and hashing it? 如何使用存储过程并对其进行散列?

Thanks. 谢谢。

If you have access to the user you can change their password prior using the Membership method: 如果您有权访问该用户,则可以在使用Membership方法之前更改其密码:

public virtual bool ChangePassword(string oldPassword, string newPassword)

You could try 你可以试试

string newPassword = user.ResetPassword();
user.ChangePassword(newPassword, "SOMENEWPASSWORD");

Then do 然后做

user.ChangePasswordQuestionAndAnswer("SOMENEWPASSWORD", question, answer);   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM