Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

WebSecurity - GeneratePasswordResetToken()


❮ WebSecurity

Definition

The GeneratePasswordResetToken() method generates a password reset token that can be sent to a user in email.


C# and VB Syntax

WebSecurity.GeneratePasswordResetToken(userName, expiration)

Parameters

Parameter Type Description
userName String The user name
expiration Integer The time in minutes until the token expires. Default is 1440 (24 hours)

Return Value

Type Description
String A reset token.

Errors and Exceptions

Any access to the WebSecurity object throws an InvalidOperationException if:

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

Remarks

Use the ResetPassword() method if the user has forgotten his password. The ResetPassword() method requires a password reset token.

A confirmation token can be created by the CreateAccount(), CreateUserAndAccount(), or GeneratePasswordResetToken() methods.

The password can be reset by code, but the common procedure is to send an email to the user (with the token and a link to a page) so he 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);
}
}
<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>

❮ WebSecurity
×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.