WebSecurity GeneratePasswordResetToken 方法
websecurity - generatepasswordresettoken()

定義
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="">
<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>
技術數據
名稱 | 值 |
---|---|
namespace | webmatrix.webdata |
assembly | webmatrix.webdata.dll |

相關文章
- ASP.NET Web Pages Razor
- ASP.NET Web Pages 布局
- ASP.NET Web Pages 文件夾
- ASP.NET Web Pages 全局文件
- ASP.NET Web Pages 文件
- ASP.NET Web Pages Email
- ASP.NET Web Pages WebSecurity 參考手冊
- ASP.NET Razor VB 循環和數組
- ASP.NET Razor VB 邏輯
- ASP.NET MVC Web 應用程序
- ASP.NET MVC 視圖
- ASP.NET MVC 數據庫
- ASP.NET MVC 模型
- ASP.NET MVC – 發布
- ASP.NET 服務器控件
- ASP.NET 事件句柄
- ASP.NET Web 表單
- ASP.NET ViewState
- ASP.NET DataList 控件
- ASP.NET 導航