WebSecurity - GeneratePasswordResetToken()
WebSecurity object
define
GeneratePasswordResetToken() The method generates a password reset token that can be sent to the user by email so the user can reset the password.
C# and VB syntax
WebSecurity.GeneratePasswordResetToken(
userName, expiration
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| userName | String | Username |
| expiration | Integer | The token expiration time, in minutes. The default is 1440 (24 hours). |
Return Value
| Type | Description |
|---|---|
| String | A reset token. |
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.ResetPassword() method to request 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