WebSecurity - GeneratePasswordResetToken ()
❮ Bảo mật Web
Sự định nghĩa
Phương thức GeneratePasswordResetToken () tạo mã thông báo đặt lại mật khẩu có thể được gửi đến người dùng trong email.
Cú pháp C # và VB
WebSecurity.GeneratePasswordResetToken(userName, expiration)
Thông số
Parameter | Type | Description |
---|---|---|
userName | String | The user name |
expiration | Integer | The time in minutes until the token expires. Default is 1440 (24 hours) |
Giá trị trả lại
Type | Description |
---|---|
String | A reset token. |
Lỗi và ngoại lệ
Bất kỳ quyền truy cập nào vào đối tượng WebSecurity đều ném ra một lỗi không hợp lệ nếu:
- Phương thức InitializeDatabaseConnection () chưa được gọi
- SimpleMembership không được khởi tạo (hoặc bị vô hiệu hóa trong cấu hình trang web)
Nhận xét
Sử dụng phương thức ResetPassword () nếu người dùng quên mật khẩu của mình. Phương thức ResetPassword () yêu cầu mã thông báo đặt lại mật khẩu .
Mã thông báo xác nhận có thể được tạo bằng các phương thức CreateAccount () , CreateUserAndAccount () hoặc GeneratePasswordResetToken () .
Mật khẩu có thể được đặt lại bằng mã, nhưng quy trình phổ biến là gửi email cho người dùng (với mã thông báo và liên kết đến một trang) để họ có thể xác nhận mật khẩu mới với mã thông báo mới:
@{
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>
❮ Bảo mật Web