This commit is contained in:
eson 2023-09-06 11:14:49 +08:00
parent 4d0081b19c
commit 5a9a23eb9c

View File

@ -59,7 +59,6 @@ button:hover {
background-color: #0056b3;
}
/* Mobile */
@media screen and (max-width: 767px) {
.container {
@ -102,31 +101,34 @@ button:hover {
</head>
<body>
<div class="container">
<h2>Reset Password</h2>
<form id="resetForm">
<div class="form-group">
<label for="new_password">New Password</label>
<input id="new_password" type="password" placeholder="New password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$">
<input id="new_password" type="password" placeholder="New password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$" title="The password must be at least 8 characters in length, and contain at least 1 number, 1 lowercase letter and 1 uppercase letter."/>
</div>
<div class="form-group">
<label for="confirm_password">Confirm Password</label>
<input id="confirm_password" type="password" placeholder="Confirm password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$">
<input id="confirm_password" type="password" placeholder="Confirm password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$" title="The password must be at least 8 characters in length, and contain at least 1 number, 1 lowercase letter and 1 uppercase letter."/>
</div>
<button type="button" onclick="resetPassword()">Reset Password</button>
</form>
</div>
<script>
function resetPassword() {
const new_password = document.getElementById("new_password").value;
const confirm_password = document.getElementById("confirm_password").value;
if (new_password !== confirm_password) {
alert("Passwords do not match");
return;
}
sha256ToBase64(new_password).then((hash) => {
const data = {
new_password: hash,
@ -144,25 +146,25 @@ function resetPassword() {
.then(data => {
if (data.code == 200 ) {
alert(data.msg);
window.location.href = "{{.HomePage}}";
{{/* window.location.href = "{{.HomePage}}"; */}}
setTimeout(function() {
window.location.href = "{{.HomePage}}";
}, 1000);
} else {
alert(data.msg);
}
})
.catch(error => {
console.error('Error:', error);
// 在这里处理其他错误情况
});
});
}
function sha256ToBase64(message) {
const msgBuffer = new TextEncoder().encode(message);
return crypto.subtle.digest('SHA-256', msgBuffer).then((hashBuffer) => {
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashBase64 = btoa(hashArray.reduce((str, byte) => str + String.fromCharCode(byte), ''));
return hashBase64;
});
}