Advertisement
daixso

PHP OOP Login System

Jul 8th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2. class Session {
  3.  
  4.     function __construct() {
  5.         //start a new session
  6.         $_SESSION["suppLogin"] = "guest";
  7.     }
  8.  
  9.     function logIn($user) {
  10.         $_SESSION["suppLogin"] = $user;
  11.     }
  12.  
  13.     function verifyLogin($user, $pass) {
  14.         $hash = hash('sha256',strtoupper($user)." insert salt here ".md5(strtolower($pass)));
  15.        
  16.         $mysqli = new mysqli("127.0.0.1","root"," hidden "," hidden ");
  17.         if($mysqli->connect_errno){
  18.             echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
  19.             return false;
  20.         }
  21.  
  22.         if(!($stmt = $mysqli->prepare("SELECT * FROM users WHERE username=(?) && password=(?)"))){
  23.             echo "Query preparation failed: (" . $mysqli->errno . ") " . $mysqli->error;
  24.             return false;
  25.         }
  26.  
  27.         if(!$stmt->bind_param("ss",$user,$hash)){
  28.             echo "Failed to bind parameters: (" . $mysqli->errno . ") " . $mysqli->error;
  29.             return false;
  30.         }
  31.  
  32.         if(!$stmt->execute()){
  33.             echo "Failed to execute statement: (" . $mysql->errno . ") " . $mysqli->error;
  34.             return false;
  35.         }
  36.  
  37.         $stmt->store_result();
  38.  
  39.         if($stmt->num_rows() != 1){
  40.             echo "The information you provided was unable to authenticate your credentials. <br />";
  41.             return false;
  42.         }
  43.  
  44.         return true;
  45.     }
  46. }
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement