WebSecurity - ResetPassword()
WebSecurity object
define
ResetPassword() The method resets the user's password using a password token.
C# and VB syntax
WebSecurity.ResetPassword(
passwordResetToken,newPassword)
Parameters
| Parameters | Type | Description |
|---|---|---|
| passwordResetToken | String | The password token |
| newpassword | String | The new password |
Return Value
| Type | Description |
|---|---|
| Boolean | Returns if the password is changed true; otherwise, returns false。 |
Errors and exceptions
In the following cases, any access to the WebSecurity object will throw an InvalidOperationException:
- InitializeDatabaseConnection() The method is not called
- SimpleMembership Not initialized (or disabled in the website configuration)
Notes
If the user has forgotten the password, use the ResetPassword method.
The ResetPassword method requires a passwordreset token。
The confirmation token can be created via the CreateAccount()、 CreateUserAndAccount() or GeneratePasswordResetToken() method.
The password can be reset via code, but the general procedure is to send an email to the user (with the token and a link to the page) so the user can confirm the new password with the 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);
}
}
Change Password
Technical data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity object