WebSecurity - สร้างPasswordResetToken()
❮ ความปลอดภัยของเว็บ
คำนิยาม
GeneratePasswordResetToken() วิธี การสร้างโทเค็นการรีเซ็ตรหัสผ่านที่สามารถส่งไปยังผู้ใช้ในอีเมล
C # และ VB ไวยากรณ์
WebSecurity.GeneratePasswordResetToken(userName, expiration)
พารามิเตอร์
Parameter | Type | Description |
---|---|---|
userName | String | The user name |
expiration | Integer | The time in minutes until the token expires. Default is 1440 (24 hours) |
คืนมูลค่า
Type | Description |
---|---|
String | A reset token. |
ข้อผิดพลาดและข้อยกเว้น
การเข้าถึงวัตถุ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>
❮ ความปลอดภัยของเว็บ