Advertisement
Guest User

Untitled

a guest
May 17th, 2018
2,238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1.     public function Login($email, $password){
  2.  
  3.         $global $con;
  4.  
  5.         // If form isn't empty
  6.         if($email != '' && $password != ''){
  7.  
  8.             // Secure user input from injection
  9.             $email = $con->real_escape_string($email);
  10.             $password = $con->real_escape_string($password);
  11.  
  12.             // Put entire list of users in a variable
  13.             $users = $con->query("SELECT id, email, password FROM users");
  14.  
  15.             // Loop entire table
  16.             while($user = $users->fetch_object()){
  17.  
  18.                 # The only way for verification is with this,
  19.                 # as both email and passwords are encrypted.
  20.                 # At least this is the only solution I came up with.
  21.                 # So to check if a user exists, I have to mirror
  22.                 # their email with one in the database,
  23.                 # scanning the entire database for users.
  24.                 //If email matches one in the database
  25.                 if(password_verify($email, $user->email)){
  26.  
  27.                     // if password matches the one currently in the loop.
  28.                     if(password_verify($password, $user->password)){
  29.  
  30.                         // Put user ID inside the session 'uid' (stands for 'user id')
  31.                         $_SESSION['uid'] = $user->id;
  32.                         header('Location: admin');
  33.  
  34.                     }else{
  35.                         // Error 1 = password incorrect
  36.                         header('Location: login/1');
  37.                     }
  38.  
  39.                 }else{
  40.                     // Error 2 = nonexistent
  41.                     header('Location: login/2');
  42.                 }
  43.  
  44.             }
  45.  
  46.         }else{
  47.             // Error 3 = inputs were empty
  48.             header('Location: login/3');
  49.         }
  50.  
  51.     }// End of Login-method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement