WebSecurity - ResetPassword()


WebSecurity 对象WebSecurity Object

Definition

ResetPassword()The method resets a user's password using a password token.


C# and VB Syntax

WebSecurity.ResetPassword(passwordResetToken,newPassword)


Parameters

Parameters Type Description
passwordResetToken String Password token
newpassword String New password


Return Value

Type Description
Boolean Returns true if the password has been changedtrue, otherwise returnsfalse。


Errors and Exceptions

In the following cases, anyWebSecurityaccess to the object will throw anInvalidOperationException:

  • InitializeDatabaseConnection()The method has not been called.
  • SimpleMembershipNot initialized (or disabled in website configuration).

Remarks

If a user has forgotten the password, please use theResetPasswordmethod.

The ResetPassword method requires a passwordreset token。

The confirmation token can beCreateAccount()、 CreateUserAndAccount()orGeneratePasswordResetToken()created by the method.

Passwords can be reset by code, but the general process is to send an email to the user (with a token and a link to the page), so that the user can confirm the new password with the 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

Name Value
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll


WebSecurity 对象WebSecurity Object Other extensions