Advertisement
Guest User

Untitled

a guest
Dec 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2. //pulls in database login credentials
  3. require_once('credentials.php');
  4. session_start();
  5.  
  6. //DEVELOPMENT PURPOSES ONLY. REMOVE BEFORE SUBMISSION!
  7. error_reporting (E_ALL);
  8. ini_set('display_errors', 1);
  9. if(!empty($_POST['username']) && !empty ($_POST['password'])) {
  10.  
  11.     $username = mysqli_real_escape_string($conn, $_POST["username"]);
  12.     //hashes user input to match against database hash
  13.     $password = password_hash(mysqli_real_escape_string($conn, $_POST["password"]), PASSWORD_BCRYPT);
  14.  
  15.     $sql = "SELECT username,password FROM Credentials.Users WHERE username = '$username' AND password = '$password'";
  16.     $result = $conn->query($sql);
  17.  
  18.     echo mysqli_error($conn);
  19.  
  20.     if ($result->num_rows > 0) {
  21.  
  22.                 $_SESSION['user'] = $username;
  23.  
  24.                 if(isset($_SESSION['user'])){
  25.                     echo 'logged in!';
  26.                 }else{
  27.                     echo 'not logged in wtf';
  28.                 }
  29.     }else{
  30.         echo 'there aint no rows brother';
  31.     }
  32. }else{
  33.     echo 'i fucked up the form';
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement