WebSecurity - ResetPassword()
WebSecurity オブジェクト
定义
ResetPassword()メソッドはパスワードトークンを使用してユーザーのパスワードをリセットします。
C# と VB 構文
WebSecurity.ResetPassword(passwordResetToken,newPassword)
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| passwordResetToken | String | 密码令牌 |
| newpassword | String | 新密码 |
返回值
| 类型 | 描述 |
|---|---|
| Boolean | パスワードが変更された場合は、戻りますtrue,否则返回false。 |
エラーと例外
以下の場合、いかなるWebSecurityオブジェクトへのアクセスでも、例外がスローされますInvalidOperationException:
- InitializeDatabaseConnection()メソッドが呼び出されていません
- SimpleMembership初期化されていない(またはサイト設定で無効)
备注
ユーザーがパスワードを忘れた場合は、次を使ってくださいResetPassword方法。
ResetPasswordメソッドはパスワードを要求します重置令牌。
確認トークンが通過可能ですCreateAccount()、 CreateUserAndAccount() 或 GeneratePasswordResetToken()方法创建。
パスワードはコードでリセットできますが、一般的なプロセスはユーザーにメールを送信することです(トークンとページへのリンクを含む)。これにより、ユーザーは新しいトークンを使用して新しいパスワードを確認できます:
@{
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="">
<input type="password" id="newPassword" name="newPassword" title="New password" />
<input type="password" id="confirmPassword" name="confirmPassword" title="Confirm new password" />
<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="">
<input type="password" id="newPassword" name="newPassword" title="New password" />
<input type="password" id="confirmPassword" name="confirmPassword" title="Confirm new password" />
<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>
技术数据
| 名称 | 值 |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity オブジェクト 其他扩展