Latest web development tutorials

WebSecurity ResetPassword method

WebSecurity objects WebSecurity objects

definition

ResetPassword () method using a password token to reset the user password.


C # and VB syntax

WebSecurity.ResetPassword( passwordResetToken,newPassword)


parameter

参数 类型 描述
passwordResetToken String 密码令牌
newpassword String 新密码


return value

类型 描述
Boolean 如果密码已更改,则返回 true ,否则返回 false


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 methods.

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