Advertisement
Guest User

Fixed Login handler

a guest
Jun 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['login-submit'])) {
  3.  
  4.     include_once "DBC.php";
  5.  
  6.     $Uname = $_POST['uname'];
  7.     $Psw = $_POST['psw'];
  8.  
  9.     if (empty($Uname) || empty($Psw)) {
  10.         header("location: ../LoginPage.php?Error=EmptyFields");
  11.         exit();
  12.     }
  13.     else {
  14.         $sql = "SELECT * FROM r66_admin WHERE username=?;";
  15.         $stmt = mysqli_stmt_init($conn);
  16.  
  17.         if (!mysqli_stmt_prepare($stmt, $sql)) {
  18.             header("location: ../LoginPage.php?Error=SQLerror");
  19.             exit();
  20.         }
  21.         else {
  22.             mysqli_stmt_bind_param($stmt, "s", $Uname);
  23.             mysqli_stmt_excecute($stmt);
  24.             $result = mysqli_stmt_get_result($stmt);
  25.  
  26.             if ($row = mysqli_fetch_assoc($result)) {
  27.                 $PswCheck = password_verify($Psw, $row['password']);
  28.  
  29.                 if ($PswCheck == false) {
  30.                     header("location: ../LoginPage.php?Error=WrongPasswordOrUsername");
  31.                     exit();
  32.                 }
  33.                 elseif ($PswCheck == true) {
  34.                     session_start();
  35.                     $_SESSION['ID'] = $row['id'];
  36.                     $_SESSION['UsName'] = $row['username'];
  37.  
  38.                     header("location: ../LoginPage.php?Login=Success");
  39.                     exit();
  40.                 }
  41.                 else {
  42.                     header("location: ../LoginPage.php?Error=WrongPasswordOrUsername");
  43.                     exit();
  44.                 }
  45.             }
  46.             else {
  47.                 header("location: ../LoginPage.php?Error=NoUser");
  48.                 exit();
  49.             }
  50.  
  51.         }
  52.     }
  53.  
  54. }
  55. else {
  56.     header("location: ../Index.php");
  57.     exit();
  58. }
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement