[英]PasswordReset() throws exception - passwordAnswer?
I have an app that I'm trying to implement the following, but can't seem to figure out how:我有一个应用程序,我正在尝试实现以下功能,但似乎无法弄清楚如何:
The problem is that I can't set the MembershipProvider to enable password retrieval as that seems to disable certficate authentication.问题是我无法将 MembershipProvider 设置为启用密码检索,因为这似乎禁用了证书身份验证。 I do have passwordReset enabled, but when I try to use it in step 2 (trying to create a new password so I can have it in plaintext to email it to the user), it throws an error:
我确实启用了密码重置,但是当我尝试在步骤 2 中使用它时(尝试创建一个新密码,以便我可以将它以明文形式提供给 email 给用户),它会引发错误:
General Error: System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown.一般错误:System.Web.HttpUnhandledException (0x80004005):引发了“System.Web.HttpUnhandledException”类型的异常。 ---> System.ArgumentNullException: Value cannot be null.
---> System.ArgumentNullException:值不能是 null。 Parameter name: passwordAnswer
参数名称:passwordAnswer
Is there any way around this?有没有办法解决?
Here's a code snippet of the relevant code:以下是相关代码的代码片段:
MembershipUser mu = Membership.GetUser(Session["UserId"], false);
string password = mu.ResetPassword();
The password is null because nothing got entered.密码是 null,因为没有输入任何内容。 In your code, just use an
if
:在您的代码中,只需使用
if
:
if (passwordAnswer==null){
//do stuff here
}
While you can write anything there, I recommend, maybe:虽然你可以在那里写任何东西,但我建议,也许:
if (passwordAnswer==null){
passwordAnswer=" ";//just a space
}
If you want it to be a generated password, research on generating random alphanumeric strings.如果您希望它是生成的密码,请研究生成随机字母数字字符串。
I was able to circumvent this issue by adding requiresQuestionAndAnswer="false" to the membership provider in my web.config:我可以通过在我的 web.config 中将 requiresQuestionAndAnswer="false" 添加到会员提供程序来规避这个问题:
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
requiresUniqueEmail="true"
connectionStringName="DB"
applicationName="Acme"
maxInvalidPasswordAttempts="3"
requiresQuestionAndAnswer="false"
enablePasswordReset="true"
minRequiredPasswordLength="15"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="3"
passwordFormat="Hashed" />
</providers>
</membership>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.