WebSecurity GeneratePasswordResetToken 方法

websecurity - generatepasswordresettoken()

websecurity 对象 websecurity 对象

定义

generatepasswordresettoken() 方法生成一个密码重置令牌,可以在电子邮件中发送给用户以便用户可以重设密码。

c# 和 vb 语法

websecurity.generatepasswordresettoken(username, expiration)

参数

参数 类型 描述
username string 用户名
expiration integer 令牌到期时间,以分钟计。默认是 1440(24 小时)

返回值

类型 描述
string 一个重置令牌。

错误和异常

在下面的情况下,任何对 websecurity 对象的访问将抛出一个 invalidoperationexception:

  • initializedatabaseconnection() 方法没有被调用
  • simplemembership 没有初始化(或者在网站配置中禁用)

备注

如果用户已忘记密码,请使用 resetpassword() 方法。resetpassword() 方法要求一个密码重置令牌。

确认令牌可通过 createaccount()、 createuserandaccount() 或 generatepasswordresettoken() 方法创建。

密码可通过代码重置,但是一般过程是发送电子邮件给用户(带有令牌和指向页面的链接),这样用户就可以通过新的令牌确认新的密码:

@{
newpassword = request["newpassword"];
confirmpassword = request["confirmpassword"];
token = request["token"];
if ispost
{
    // input testing is ommitted here to save space
    retunvalue = resetpassword(token, newpassword);
}
}
<h1>change password</h1>

<form method="post" action="">

<label for="newpassword">new password:</label>
<input type="password" id="newpassword" name="newpassword" title="new password" />

<label for="confirmpassword">confirm password:</label>
<input type="password" id="confirmpassword" name="confirmpassword" title="confirm new password" />

<label for="token">pasword token:</label>
<input type="text" id="token" name="token" title="password token" />

<p class="form-actions">
<input type="submit" value="change password" title="change password" />
</p>

</form>

技术数据

名称
namespace webmatrix.webdata
assembly webmatrix.webdata.dll

websecurity 对象 websecurity 对象
相关文章