Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.35 KB | None | 0 0
  1. <?php
  2. //check logged in/cookies/etc
  3. class login {
  4.  
  5.    function qdb_check_login_info($username, $password, $access) {
  6.       require_once('mysql.php');
  7.       $find_user = mysql_query("SELECT * FROM $member WHERE username='$username'");
  8.       if(!$find_user){
  9.          return false;
  10.       }
  11.  
  12.       $user_info = mysql_fetch_array($find_user);
  13.       $user_access = $user_info['access'];
  14.  
  15.       if($password != $user_info['password']) {
  16.          return false;
  17.       }
  18.       if($access != $user_info['access']) {
  19.          return false;
  20.       }
  21. //if password is correct and access is correct
  22.    return true;
  23. }
  24. }
  25.    
  26.    if(isset($_SESSION['username'])) {
  27.       $un = $_SESSION['username'];
  28.       if(isset($_SESSION['password'])) {
  29.          $pw = $_SESSION['password'];
  30.       }
  31.    else {
  32.       unset($_SESSION['username']);
  33.       return false;
  34.    }
  35.  
  36.    if(isset($_SESSION['access'])){
  37.       $ac = $_SESSION['access'];
  38.    }
  39.    else {
  40.       unset($_SESSION['username']);
  41.       unset($_SESSION['password']);
  42.       return false;
  43.    }
  44.         //Username, password, and access are set, check match with db here
  45.    if(qdb_check_login_info($un, $pw, $ac) == false){
  46.       $inTwoMonths = time() - 60;
  47.       unset($_SESSION['username']);
  48.       unset($_SESSION['password']);
  49.       unset($_SESSION['access']);
  50.       return false;
  51.    }
  52.    else {
  53.       return true;
  54.    }
  55.    
  56.    
  57.         if(isset($_COOKIE['username'])) {
  58.         $un = $_COOKIE['username'];
  59.         if(isset($_COOKIE['password'])) {
  60.             $pw = $_COOKIE['password'];
  61.         }
  62.         else {
  63.             $inTwoMonths = time() - 60;
  64.             setcookie('username', '', $inTwoMonths);
  65.             return false; }
  66.        
  67.         if(isset($_COOKIE['access'])){
  68.             $ac = $_COOKIE['access'];
  69.         }
  70.         else {
  71.             $inTwoMonths = time() - 60;
  72.             setcookie('username', '', $inTwoMonths);
  73.             setcookie('password', '', $inTwoMonths);
  74.             return false;
  75.         }
  76.         //Username, password, and access are set, check match with db here
  77.         if(qdb_check_login_info($un, $pw, $ac) == false){
  78.         $inTwoMonths = time() - 60;
  79.         setcookie('username', '', $inTwoMonths);
  80.         setcookie('password', '', $inTwoMonths);
  81.         setcookie('access', '', $inTwoMonths);
  82.         return false;
  83.         }
  84.         else
  85.         {
  86.         $_SESSION['username'] = $un;
  87.         $_SESSION['password'] = $pw;
  88.         $_SESSION['access'] = $ac;
  89.         return true;
  90.         }
  91.     }
  92.  
  93.  
  94. }
  95.  
  96.  
  97.  
  98. //Login
  99. function qdb_login($username, $password){
  100. require_once('mysql.php');
  101. $find_user = mysql_query("SELECT * FROM $member WHERE username='$username'") or die('Username does not exist');
  102. $user_info = mysql_fetch_array($find_user);
  103. $user_access = $user_info['access'];
  104. if($username == $user_info['username']) {
  105.     if($password == $user_info['password']) {
  106.     //If username and password are correct
  107.     $inTwoMonths = 60 * 60 * 24 * 60 + time();
  108.     setcookie('username', $username, $inTwoMonths);
  109.     setcookie('password', $password, $inTwoMonths);
  110.     setcookie('access', $user_access, $inTwoMonths);
  111.     $_SESSION['username'] = $username;
  112.     $_SESSION['password'] = $password;
  113.     $_SESSION['access'] = $user_access;
  114.     return 'Logged in successfully, ' . $username . '.';
  115.     }
  116.     else
  117.     {
  118.     //If username is correct, password is incorrect
  119.     return 'The password you entered for ' . $username . ' was incorrect, please try again.';
  120.     }
  121. }
  122. else
  123. {
  124. //if username is incorrect, no need to check if password is correct
  125. return 'The username you entered was not found, please try again';
  126. }
  127.  
  128. };
  129.  
  130. $login = new login;
  131.  
  132. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement