Advertisement
Venciity

Untitled

May 6th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. public function getCurrentUserId(){
  2.         $username = $_SESSION['username'];
  3.         $statement = self::$db->prepare("SELECT id FROM users where username = ?");
  4.         $statement->bind_param("s", $username);
  5.         $statement->execute();
  6. }
  7.  
  8.  
  9. // AccountsModel.php
  10. public function login($username, $password){
  11.         $statement = self::$db->prepare("SELECT Id, username, pass_hash FROM Users WHERE Username = ?");
  12.         $statement->bind_param("s", $username);
  13.         $statement->execute();
  14.         $result = $statement->get_result()->fetch_assoc();
  15.         if(password_verify($password, $result['pass_hash'])){
  16.             return true;
  17.         }
  18.  
  19.         return false;
  20. }
  21.  
  22.  
  23. //AccountsController.php
  24. public function login(){
  25.         if($this->isPost){
  26.             $username = $_POST['username'];
  27.             $password = $_POST['password'];
  28.             $isLoggedIn = $this->db->login($username, $password);
  29.             if($isLoggedIn){
  30.                 $_SESSION['username'] = $username;
  31.                 $this->addInfoMessage("Successfully login.");
  32.                 return $this->redirect("home");
  33.             } else {
  34.                 $this->addErrorMessage("Login error.");
  35.             }
  36.         }
  37.  
  38.         $this->renderView(__FUNCTION__);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement