วิธี WebSecurity GeneratePasswordResetToken
คำจำกัดความ
GeneratePasswordResetToken () วิธีการสร้างสัญลักษณ์การรีเซ็ตรหัสผ่านจะถูกส่งให้กับผู้ใช้ใน e-mail เพื่อให้ผู้ใช้สามารถตั้งค่ารหัสผ่าน
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 |
วัตถุ WebSecurity