WebSecurity – GeneratePasswordResetToken()
❮ WebSecurity
Definice
Metoda GeneratePasswordResetToken() generuje token pro resetování hesla, který lze odeslat uživateli e-mailem.
Syntaxe C# a VB
WebSecurity.GeneratePasswordResetToken(userName, expiration)
Parametry
Parameter | Type | Description |
---|---|---|
userName | String | The user name |
expiration | Integer | The time in minutes until the token expires. Default is 1440 (24 hours) |
Návratová hodnota
Type | Description |
---|---|
String | A reset token. |
Chyby a výjimky
Jakýkoli přístup k objektu WebSecurity vyvolá výjimku InvalidOperationException , pokud:
- Metoda InitializeDatabaseConnection() nebyla volána
- SimpleMembership není inicializováno (nebo zakázáno v konfiguraci webu)
Poznámky
Pokud uživatel zapomněl heslo, použijte metodu ResetPassword() . Metoda ResetPassword() vyžaduje token pro resetování hesla .
Token potvrzení lze vytvořit metodami CreateAccount() , CreateUserAndAccount() nebo GeneratePasswordResetToken() .
Heslo lze resetovat kódem, ale běžným postupem je poslat uživateli e-mail (s tokenem a odkazem na stránku), aby mohl potvrdit nové heslo pomocí nového tokenu:
@{
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