Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 重置用户';asp.net中的安全信息(Q&A)_C#_Asp.net_Security_Passwords_Asp.net Membership - Fatal编程技术网

C# 重置用户';asp.net中的安全信息(Q&A)

C# 重置用户';asp.net中的安全信息(Q&A),c#,asp.net,security,passwords,asp.net-membership,C#,Asp.net,Security,Passwords,Asp.net Membership,我想通过调用ChangePasswordQuestionAndAnswer方法来更改用户的密码问答 MembershipUser user = Membership.GetUser(userName); string password = user.GetPassword(); // error here string sQuestion = DropDownList1.SelectedValue.ToString(); string sAnswer = txtAnswer.Text.ToStr

我想通过调用ChangePasswordQuestionAndAnswer方法来更改用户的密码问答

MembershipUser user = Membership.GetUser(userName);
string password = user.GetPassword(); // error here
string sQuestion = DropDownList1.SelectedValue.ToString();
string sAnswer = txtAnswer.Text.ToString();
user.ChangePasswordQuestionAndAnswer(password, sQuestion, sAnswer);

但我是一名行政人员;我无法传递用户的密码,因为我不知道它。

既然您已经要求用户输入数据,为什么不再次要求输入密码?然后您可以使用相同的代码,只需将密码设置为文本框的值

string password = txtPassword.Text;
另一种方法是自动重置密码,然后要求用户将其更改为更好的密码选择:

MembershipUser user = Membership.GetUser(userName);
string password = user.ResetPassword();
string sQuestion = DropDownList1.SelectedValue.ToString();
string sAnswer = txtAnswer.Text.ToString();
user.ChangePasswordQuestionAndAnswer(password, sQuestion, sAnswer);

后者不是一个很好的解决方案,因为它需要在此代码之后执行额外的步骤。

请将您的提供商配置数据放入,您可能已启用PasswordRetrieval为false和passwordFormat=“hashed”,如果您更改这些密码,您将能够检索密码,但这意味着安全性较低。简单的解决方案是让用户提供密码并选择新的Q&A。数据库是现有数据库。它被设置为passwordFormat=“hash”。我正在升级应用程序,因此无法更改。我更倾向于将密码更改为随机16个字符的密码,更改机密问题和答案,并让所有用户重置密码。当然,正如你所说的,另一个选择很烦人。不,我的程序有一个管理部分。用户无法访问它。我想要一个管理员来重置它。