Advertisement
ZacharyVincze

Login System

Jul 27th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. include_once "includes/functions.php";
  4. include_once "includes/db_connect.php";
  5.  
  6. sec_session_start();
  7.  
  8. $username = $_POST['username'];
  9. $password = $_POST['password'];
  10.  
  11. if ($username && $password) {
  12.    
  13.     $query = "SELECT password, rank FROM user WHERE username=?";
  14.    
  15.     $result = $connect->prepare($query);
  16.     $result->bind_param('s', $username);
  17.     $result->execute();
  18.  
  19.     $result->bind_result($dbpassword, $dbrank);
  20.     $result->store_result();
  21.     $result->fetch();
  22.    
  23.     $numrows = $result->num_rows();
  24.    
  25.     if($numrows !=0) {
  26.         $hash = password_hash($password, PASSWORD_DEFAULT);
  27.         $dbusername = $username;
  28.         if ($username == $dbusername && password_verify($password, $dbpassword)) {
  29.             echo "Login successful. <br><br> <a href='membersarea.php'>Click here to enter the members area</a>";
  30.             $_SESSION['username'] = $dbusername;
  31.             $_SESSION['rank'] = $dbrank;
  32.         } else {
  33.             echo "Incorrect password...";
  34.             echo $hash;
  35.         }
  36.     } else {
  37.         die ("That username doesn't exist...");
  38.     }
  39. } else {
  40.     die ("Please enter a username and password...");
  41. }
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement