WebSecurity - GeneratePasswordResetToken()
WebSecurity オブジェクト
定义
GeneratePasswordResetToken()メソッドはパスワードリセットトークンを生成し、ユーザーがパスワードをリセットできるように電子メールでユーザーに送信できます。
C# と VB 構文
WebSecurity.GeneratePasswordResetToken(userName, expiration)
参数
| 参数 | 类型 | 描述 |
|---|---|---|
| userName | String | 用户名 |
| expiration | Integer | トークンの有効期限(分単位)。デフォルトは 1440(24 時間)です。 |
返回值
| 类型 | 描述 |
|---|---|
| String | リセットトークン |
エラーと例外
以下の場合、いかなる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 オブジェクト 其他扩展