Skip to content
This repository was archived by the owner on Mar 2, 2025. It is now read-only.

Commit 7812b4b

Browse files
author
Dipankar
committed
🔒 Implement session timeout feature and update password validation criteria
1 parent 0172278 commit 7812b4b

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

‎script/dashboard.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,16 @@ document.addEventListener(
228228
}
229229
}
230230
);
231+
// Add session timeout
232+
let sessionTimeout;
233+
234+
function resetSessionTimeout() {
235+
clearTimeout(sessionTimeout);
236+
sessionTimeout = setTimeout(() => {
237+
signOut(auth);
238+
window.location.href = "index.html";
239+
}, 1 * 10 * 1000); // 10 seconds
240+
}
241+
242+
document.addEventListener('mousemove', resetSessionTimeout);
243+
document.addEventListener('keypress', resetSessionTimeout);

‎script/index.js‎

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { initializeApp } from "https://www.gstatic.com/firebasejs/9.16.0/firebas
33
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword, onAuthStateChanged, signOut } from "https://www.gstatic.com/firebasejs/9.16.0/firebase-auth.js";
44

55
// Your Firebase configuration
6-
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
76
const firebaseConfig = {
87
apiKey: "AIzaSyCf3OuJ3LfQIOrY_ytB-VMwPTm2jaKIBJ4",
98
authDomain: "ubercoders.firebaseapp.com",
@@ -26,17 +25,14 @@ signupForm.addEventListener("submit", async (e) => {
2625
const username = document.getElementById("signup-username").value.trim();
2726
const email = document.getElementById("signup-email").value.trim();
2827
const password = document.getElementById("signup-password").value;
28+
2929
function validatePassword(password) {
30-
// At least 8 characters long
31-
// Contains uppercase and lowercase letters
32-
// Contains at least one number
33-
// Contains at least one special character
34-
const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
35-
return passwordRegex.test(password);
36-
}
30+
// At least 6 characters long
31+
return password.length >= 6;
32+
}
3733

3834
if (!validatePassword(password)) {
39-
alert("Password must be at least 8 characters long, contain uppercase and lowercase letters, at least one number, and at least one special character.");
35+
alert("Password must be at least 6 characters long.");
4036
return;
4137
}
4238

@@ -81,23 +77,25 @@ loginForm.addEventListener("submit", async (e) => {
8177
});
8278

8379
// Detect User Authentication State
84-
if (window.location.pathname.endsWith("index.html") || window.location.pathname === "/") {
85-
if (user) {
86-
// User is logged in
87-
console.log("User is logged in:", user.email);
88-
// If already on login or signup page, redirect to dashboard
89-
if (window.location.href.includes("index.html") || window.location.href.endsWith("/")) {
90-
window.location.href = "dashboard.html";
91-
}
92-
} else {
93-
// User is logged out
94-
console.log("User is logged out");
95-
// If on dashboard page, redirect to login page
96-
if (window.location.href.includes("dashboard.html")) {
97-
window.location.href = "index.html";
80+
onAuthStateChanged(auth, (user) => {
81+
if (window.location.pathname.endsWith("index.html") || window.location.pathname === "/") {
82+
if (user) {
83+
// User is logged in
84+
console.log("User is logged in:", user.email);
85+
// If already on login or signup page, redirect to dashboard
86+
if (window.location.href.includes("index.html") || window.location.href.endsWith("/")) {
87+
window.location.href = "dashboard.html";
88+
}
89+
} else {
90+
// User is logged out
91+
console.log("User is logged out");
92+
// If on dashboard page, redirect to login page
93+
if (window.location.href.includes("dashboard.html")) {
94+
window.location.href = "index.html";
95+
}
9896
}
9997
}
100-
};
98+
});
10199

102100
// Handle Log Out
103101
const logoutButton = document.getElementById("logout-button");

0 commit comments

Comments
 (0)