Metoda WebSecurity ResetPassword
definicje
Metoda ResetPassword () przy użyciu tokena hasło zresetować hasło użytkownika.
C # i VB składni
WebSecurity.ResetPassword( passwordResetToken,newPassword)
parametry
参数 | 类型 | 描述 |
---|---|---|
passwordResetToken | String | 密码令牌 |
newpassword | String | 新密码 |
Wartość zwracana
类型 | 描述 |
---|---|
Boolean | 如果密码已更改,则返回 true ,否则返回 false 。 |
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.
Metoda ResetPassword 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>
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