WebSecurity – ResetPassword ()


❮ WebSecurity

Definice

Metoda ResetPassword() resetuje uživatelské heslo pomocí tokenu hesla.


Syntaxe C# a VB

WebSecurity.ResetPassword(passwordResetToken,newPassword)

Parametry

Parameter Type Description
passwordResetToken String The password token
newpassword String The new password

Návratová hodnota

Type Description
Boolean true if the password was changed, otherwise false

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