Guest User

code snippet

a guest
May 16th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. public function loggingIn(){
  2.     if(!empty($this->m_sUsername) && !empty($this->m_sPassword)){
  3.         $PDO = Db::getInstance();
  4.         $stmt = $PDO->prepare("SELECT * FROM users WHERE username = :username");
  5.         $stmt->bindValue(":username", $this->m_sUsername, PDO::PARAM_STR);
  6.         $stmt->execute();
  7.  
  8.         if($stmt->rowCount() > 0){
  9.             $result = $stmt->fetch(PDO::FETCH_ASSOC);
  10.             $password = $this->m_sPassword;
  11.             $hash = $result['password'];
  12.  
  13.             if(password_verify($password, $hash)){
  14.                 session_start();
  15.                 $_SESSION["loggedIn"] = $result['usersid'];
  16.                 session_write_close();
  17.                 return true;
  18.             }else{
  19.                 return false;
  20.             }
  21.         }
  22.     }
  23. }
Add Comment
Please, Sign In to add comment