skylight_animation

Web Storage - sessionStorage | login.js

Sep 4th, 2020
4,653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkLoginStatus(page){
  2.     username = sessionStorage.getItem("username");
  3.     if (page == 'login') {
  4.         if (username) {
  5.             window.location.href = "dashboard.html";
  6.         }  
  7.     }else if (page == 'dashboard') {
  8.         if (!username) {
  9.             window.location.href = "login.html";
  10.         }else{
  11.             $('#username').text(username);
  12.         }
  13.     }else{
  14.         window.location.href = "login.html";
  15.     }
  16. }
  17.  
  18. function login(){
  19.     var username = $('#username').val();
  20.     var password = $('#password').val();
  21.  
  22.     if(password != '12341234'){
  23.         alert('Password Wrong!!!');
  24.     }else if(username != 'admin'){
  25.         alert('Username not exist!!!');
  26.     }else if (username == 'admin' && password == '12341234') {
  27.         sessionStorage.setItem("username", "admin");
  28.         window.location.href = "dashboard.html";
  29.     }
  30. }
  31.  
  32. function logout(){
  33.     sessionStorage.removeItem("username");
  34.     window.location.href = "login.html";
  35. }
Advertisement
Add Comment
Please, Sign In to add comment