This commit is contained in:
eson
2023-09-05 15:00:45 +08:00
parent d9daae7829
commit 81ad6122a7
14 changed files with 321 additions and 57 deletions

View File

@@ -102,28 +102,70 @@ button:hover {
</head>
<body>
<div class="container">
<h2>Reset Password</h2>
<form>
<form id="resetForm">
<div class="form-group">
<label for="newPassword">New Password</label>
<input id="newPassword" type="password" placeholder="New password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$">
<label for="new_password">New Password</label>
<input id="new_password" type="password" placeholder="New password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$">
</div>
<div class="form-group">
<label for="confirmPassword">Confirm Password</label>
<input id="confirmPassword" type="password" placeholder="Confirm password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$">
<label for="confirm_password">Confirm Password</label>
<input id="confirm_password" type="password" placeholder="Confirm password" required pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$">
</div>
<button type="submit">Reset Password</button>
<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,
reset_token: "{{.ResetToken}}",
};
fetch('{{.ResetPasswordLink}}', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => {
if (response.ok) {
console.log('Password reset successful');
//
} else {
console.error('Password reset failed');
//
}
})
.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;
});
}
</script>
</body>
</html>