-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforgot-password.html
More file actions
69 lines (59 loc) · 2.56 KB
/
forgot-password.html
File metadata and controls
69 lines (59 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forgot Password - Smart Voice Calculator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body class="forgot-password-background">
<div class="container">
<header>
<h1>Forgot Password</h1>
<p class="subtitle">Enter your username and email to reset your password.</p>
</header>
<div class="error" id="error-message"></div>
<form id="reset-form">
<label for="reset-username">Username:</label>
<input type="text" id="reset-username" required>
<label for="reset-email">Email:</label>
<input type="email" id="reset-email" required>
<label for="new-password">New Password:</label>
<input type="password" id="new-password" required>
<button type="submit">Reset Password</button>
</form>
<p class="redirect-text">Remembered your password? <a href="index.html">Login here</a>.</p>
</div>
<script src="auth.js"></script>
<script>
if (checkAuth()) {
window.location.href = 'home.html';
}
const resetForm = document.getElementById('reset-form');
const errorMessage = document.getElementById('error-message');
resetForm.addEventListener('submit', (event) => {
event.preventDefault();
const username = document.getElementById('reset-username').value.trim();
const email = document.getElementById('reset-email').value.trim();
const newPassword = document.getElementById('new-password').value.trim();
let users = {};
// Attempt to retrieve users from local storage
try {
users = JSON.parse(localStorage.getItem('users')) || {};
} catch (error) {
console.error("Failed to parse users from local storage:", error);
}
// Check if username and email match
if (users[username] && users[username].email === email) {
users[username].password = newPassword;
localStorage.setItem('users', JSON.stringify(users));
alert("Password updated successfully! You can now log in.");
window.location.href = 'index.html';
} else {
errorMessage.textContent = "Username or email is incorrect.";
errorMessage.style.color = 'red';
}
});
</script>
</body>
</html>