Latest web development tutorials

WebSecurity GeneratePasswordResetToken method

WebSecurity objects WebSecurity objects

definition

GeneratePasswordResetToken () method generates a password reset token can be sent to the user in an e-mail so that the user can reset the password.


C # and VB syntax

WebSecurity.GeneratePasswordResetToken( userName, expiration )


parameter

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


return value

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


Errors and exceptions

In the following scenario, any access to WebSecurity object will throw an InvalidOperationException:

  • InitializeDatabaseConnection () method has not been called
  • SimpleMembership not initialized (or disabled in the site configuration)

Remark

If you've forgotten your password, please use ResetPassword () method. ResetPassword () method requires a password reset token.

Confirm token by CreateAccount (), CreateUserAndAccount () or GeneratePasswordResetToken () method creates.

The password can be reset by the code, but the general procedure is to send e-mail to the user (with a token and a link pointing to a page), so the user can confirm the new password by a new token:

@{
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>


Technical data

名称
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll


WebSecurity objects WebSecurity objects