วิธี WebSecurity ResetPassword
คำจำกัดความ
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="">
<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 |
วัตถุ WebSecurity