Advertisement
michaelyuen

Untitled

Apr 24th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start();
  3. require 'conn.php';
  4.  
  5. if (isset($_POST['login'])) {
  6.    
  7.     $uname = $_POST['username'];
  8.     $pwd = $_POST['password'];
  9.     $sql = "SELECT * FROM chat WHERE username = ?";
  10.     $stmt = $db->prepare($sql);
  11.     // you just need to find matching username
  12.     $stmt->bind_param("s", $uname);
  13.     $stmt->execute();
  14.     $result = $stmt->get_result();
  15.     $re = $result->fetch_assoc()
  16.     // check if matching username is found, then verify hashed password from database
  17.     if ($re && password_verify($pwd, $re['password'])) {
  18.         $_SESION['username'] = $re['username'];
  19.         exit(header('location: home.php'));
  20.     } else {
  21.         echo "wrong username/password";    
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement