rithwikreal commited on
Commit
168404c
·
verified ·
1 Parent(s): 5e4ebfc

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +19 -25
script.js CHANGED
@@ -1,41 +1,35 @@
1
- // Redirect if not logged in
 
 
 
 
2
  if (window.location.pathname.includes("app.html")) {
3
- if (!localStorage.getItem("loggedInUser")) {
4
  window.location.href = "index.html";
5
  }
6
  }
7
 
8
- // Signup
9
- function signup() {
10
- const user = username.value;
11
- const pass = password.value;
12
-
13
- if (!user || !pass) {
14
- message.innerText = "Please fill all fields";
15
- return;
16
- }
17
-
18
- localStorage.setItem(user, pass);
19
- message.innerText = "Signup successful! You can now login.";
20
- }
21
-
22
- // Login
23
  function login() {
24
- const user = username.value;
25
- const pass = password.value;
26
-
27
- const storedPass = localStorage.getItem(user);
28
 
29
- if (storedPass === pass) {
30
- localStorage.setItem("loggedInUser", user);
31
  window.location.href = "app.html";
32
  } else {
33
- message.innerText = "Invalid credentials ";
34
  }
35
  }
36
 
37
  // Logout
38
  function logout() {
39
- localStorage.removeItem("loggedInUser");
40
  window.location.href = "index.html";
41
  }
 
 
 
 
 
 
1
+ // Fixed credentials
2
+ const FIXED_USERNAME = "people";
3
+ const FIXED_PASSWORD = "home";
4
+
5
+ // Protect app.html
6
  if (window.location.pathname.includes("app.html")) {
7
+ if (!sessionStorage.getItem("isLoggedIn")) {
8
  window.location.href = "index.html";
9
  }
10
  }
11
 
12
+ // Login function
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  function login() {
14
+ const user = document.getElementById("username").value;
15
+ const pass = document.getElementById("password").value;
16
+ const message = document.getElementById("message");
 
17
 
18
+ if (user === FIXED_USERNAME && pass === FIXED_PASSWORD) {
19
+ sessionStorage.setItem("isLoggedIn", "true");
20
  window.location.href = "app.html";
21
  } else {
22
+ message.innerText = "Invalid username or password";
23
  }
24
  }
25
 
26
  // Logout
27
  function logout() {
28
+ sessionStorage.removeItem("isLoggedIn");
29
  window.location.href = "index.html";
30
  }
31
+
32
+ // Disable signup (optional safety)
33
+ function signup() {
34
+ alert("Signup is disabled. Use the provided demo credentials.");
35
+ }