Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.67 KB | None | 0 0
  1. <?php
  2.  
  3. //echo "<script type='text/javascript'>alert('$m');</script>";
  4. session_start(); // Starting Session
  5.  
  6. $error = ''; // Variable To Store Error Message
  7.  
  8.  
  9. if (isset($_POST['submit'])) {
  10.     $username = $_POST['username'];
  11.     $password = $_POST['password']; //md5
  12.  
  13.     $options = ['cost' => 12,];
  14.     $passwordHash = password_hash($password, PASSWORD_BCRYPT, $options);
  15.  //   echo '--->' . '' . $passwordHash;
  16.    
  17.     if (password_verify($password, $passwordHash))
  18.     {
  19.        
  20.        
  21.         $connection = mysqli_connect("localhost", "root", "", "ddt_db");
  22.  
  23.         if (mysqli_connect_errno())
  24.             {
  25.             mysqli_close($connection);
  26.         } else {
  27.  
  28.             $result = "SELECT * FROM member WHERE username=? AND password=?";
  29.  
  30.  
  31.             $stmt = mysqli_stmt_init($connection);
  32.  
  33.  
  34.             if (mysqli_stmt_prepare($stmt, $result) == TRUE) {
  35.  
  36.                 mysqli_stmt_bind_param($stmt, "ss", $username, $password);
  37.  
  38.                 mysqli_stmt_execute($stmt);
  39.  
  40.                 mysqli_stmt_store_result($stmt);
  41.  
  42.                 $res = mysqli_stmt_fetch($stmt);
  43.  
  44.                 //    mysqli_stmt_fetch($stmt1);
  45.  
  46.                 $rows = mysqli_stmt_num_rows($stmt);
  47.                 //$arr = mysqli_stmt_fetch($stmt1);
  48.                 //print_r($arr);
  49.                 //$rows2 = mysqli_num_rows($result2);
  50.                 //
  51.                 //
  52.  //echo 'lafhdjksljdsfhsfdjhlfsdkjsdfh';
  53.                
  54.                
  55.                 if ($rows == 1)
  56.                     {
  57.                     echo "Sure";
  58.                     $_SESSION['login_user'] = $username;
  59.                     $result2 = "SELECT * FROM member WHERE username= '$username'";
  60.                     $res = mysqli_query($connection, $result2);
  61.                     $rest = mysqli_fetch_array($res);
  62.                     //$user = mysqli_stmt_execute($stmt1);
  63.  
  64.                     if ($rest['admin'] == 1) {
  65.                         echo "admin";
  66.                         //  header("location: pages/admin.php");
  67.                     } else {
  68.                         //echo "not admin";
  69.                         header("location: testLogin.php");
  70.                     }
  71.                 } else {
  72.                     if ($rows == 0) {
  73.                         ?>
  74.                         <script>
  75.                             alert('Email or Password is invalid')
  76.                         </script>;
  77.                         <?php
  78.  
  79.                         //$error = "Username or Password is invalid";  Doesnt work
  80.                     }
  81.                 }
  82.             }
  83.         }
  84.        
  85.     }
  86.     else
  87.         {
  88.  
  89.         echo 'Invalid password.';
  90.     }
  91. }
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement