WebSecurity - รีเซ็ตรหัสผ่าน()
❮ ความปลอดภัยของเว็บ
คำนิยาม
ResetPassword() วิธี การรีเซ็ตรหัสผ่านผู้ใช้โดยใช้โทเค็นรหัสผ่าน
C # และ VB ไวยากรณ์
WebSecurity.ResetPassword(passwordResetToken,newPassword)
พารามิเตอร์
Parameter | Type | Description |
---|---|---|
passwordResetToken | String | The password token |
newpassword | String | The new password |
คืนมูลค่า
Type | Description |
---|---|
Boolean | true if the password was changed, otherwise 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="">
<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>
❮ ความปลอดภัยของเว็บ