WebSecurity - GeneratePasswordResetToken()


❮ Sicurezza web

Definizione

Il metodo GeneratePasswordResetToken() genera un token di reimpostazione della password che può essere inviato a un utente tramite posta elettronica.


Sintassi C# e VB

WebSecurity.GeneratePasswordResetToken(userName, expiration)

Parametri

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

Valore di ritorno

Type Description
String A reset token.

Errori ed eccezioni

Qualsiasi accesso all'oggetto WebSecurity genera un'eccezione InvalidOperationException se:

  • Il metodo InitializeDatabaseConnection() non è stato chiamato
  • SimpleMembership non è inizializzato (o disabilitato nella configurazione del sito Web)

Osservazioni

Utilizzare il metodo ResetPassword() se l'utente ha dimenticato la password. Il metodo ResetPassword() richiede un token di reimpostazione della password .

Un token di conferma può essere creato dai metodi CreateAccount() , CreateUserAndAccount() o GeneratePasswordResetToken() .

La password può essere reimpostata tramite codice, ma la procedura comune è inviare una mail all'utente (con il token e un link ad una pagina) in modo che possa confermare la nuova password con il nuovo 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>

❮ Sicurezza web