WebSecurity - ResetPassword ()
❮ Bảo mật Web
Sự định nghĩa
Phương thức ResetPassword () đặt lại mật khẩu người dùng bằng mã thông báo mật khẩu.
Cú pháp C # và VB
WebSecurity.ResetPassword(passwordResetToken,newPassword)
Thông số
Parameter | Type | Description |
---|---|---|
passwordResetToken | String | The password token |
newpassword | String | The new password |
Giá trị trả lại
Type | Description |
---|---|
Boolean | true if the password was changed, otherwise false |
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 pháp 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