Latest web development tutorials

Metoda WebSecurity GeneratePasswordResetToken

obiekty WebSecurity obiekty WebSecurity

definicje

GeneratePasswordResetToken () metoda generuje hasło tokenu resetowania mogą być wysyłane do użytkownika w wiadomości e-mail, dzięki czemu użytkownik może zresetować hasło.


C # i VB składni

WebSecurity.GeneratePasswordResetToken( userName, expiration )


parametry

参数 类型 描述
userName String 用户名
expiration Integer 令牌到期时间,以分钟计。默认是 1440(24 小时)


Wartość zwracana

类型 描述
String 一个重置令牌。


Błędy i wyjątki

W poniższym scenariuszu, każdy dostęp do obiektu WebSecurity rzuci InvalidOperationException:

  • Metoda InitializeDatabaseConnection () nie została wywołana
  • Nie SimpleMembership inicjowane (lub wyłączone w konfiguracji stronie)

uwaga

Jeśli nie pamiętasz hasła, skorzystaj z metody ResetPassword (). ResetPassword () metoda wymaga tokena resetowania hasła.

Potwierdź znacznik za CreateAccount (), CreateUserAndAccount () lub GeneratePasswordResetToken () metoda tworzy.

Hasło można zresetować kodu, ale ogólna procedura jest wysłać e-mail do użytkownika (z tokenem i link wskazujący na stronie), dzięki czemu użytkownik może potwierdzić nowe hasło nowego tokena:

@{
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>


dane techniczne

名称
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll


obiekty WebSecurity obiekty WebSecurity