Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.23 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.  
  27.     if(isset($_SESSION['username'])) {
  28.         $un = $_SESSION['username'];
  29.         if(isset($_SESSION['password'])) {
  30.             $pw = $_SESSION['password'];
  31.         }
  32.         else {
  33.             unset($_SESSION['username']);
  34.             return false; }
  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.         {
  54.         return true;
  55.         }
  56.     }
  57.    
  58.    
  59.         if(isset($_COOKIE['username'])) {
  60.         $un = $_COOKIE['username'];
  61.         if(isset($_COOKIE['password'])) {
  62.             $pw = $_COOKIE['password'];
  63.         }
  64.         else {
  65.             $inTwoMonths = time() - 60;
  66.             setcookie('username', '', $inTwoMonths);
  67.             return false; }
  68.        
  69.         if(isset($_COOKIE['access'])){
  70.             $ac = $_COOKIE['access'];
  71.         }
  72.         else {
  73.             $inTwoMonths = time() - 60;
  74.             setcookie('username', '', $inTwoMonths);
  75.             setcookie('password', '', $inTwoMonths);
  76.             return false;
  77.         }
  78.         //Username, password, and access are set, check match with db here
  79.         if(qdb_check_login_info($un, $pw, $ac) == false){
  80.         $inTwoMonths = time() - 60;
  81.         setcookie('username', '', $inTwoMonths);
  82.         setcookie('password', '', $inTwoMonths);
  83.         setcookie('access', '', $inTwoMonths);
  84.         return false;
  85.         }
  86.         else
  87.         {
  88.         $_SESSION['username'] = $un;
  89.         $_SESSION['password'] = $pw;
  90.         $_SESSION['access'] = $ac;
  91.         return true;
  92.         }
  93.     }
  94.  
  95.  
  96. }
  97.  
  98.  
  99.  
  100. //Login
  101. function qdb_login($username, $password){
  102. require_once('mysql.php');
  103. $find_user = mysql_query("SELECT * FROM $member WHERE username='$username'") or die('Username does not exist');
  104. $user_info = mysql_fetch_array($find_user);
  105. $user_access = $user_info['access'];
  106. if($username == $user_info['username']) {
  107.     if($password == $user_info['password']) {
  108.     //If username and password are correct
  109.     $inTwoMonths = 60 * 60 * 24 * 60 + time();
  110.     setcookie('username', $username, $inTwoMonths);
  111.     setcookie('password', $password, $inTwoMonths);
  112.     setcookie('access', $user_access, $inTwoMonths);
  113.     $_SESSION['username'] = $username;
  114.     $_SESSION['password'] = $password;
  115.     $_SESSION['access'] = $user_access;
  116.     return 'Logged in successfully, ' . $username . '.';
  117.     }
  118.     else
  119.     {
  120.     //If username is correct, password is incorrect
  121.     return 'The password you entered for ' . $username . ' was incorrect, please try again.';
  122.     }
  123. }
  124. else
  125. {
  126. //if username is incorrect, no need to check if password is correct
  127. return 'The username you entered was not found, please try again';
  128. }
  129.  
  130. };
  131.  
  132. $login = new login;
  133.  
  134. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement