Advertisement
muhfadzrin

Login_model.php

Feb 28th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. class Login_model {
  4.     private $db_table = 'users';
  5.     private $db;
  6.  
  7.     public function __construct()
  8.     {
  9.         $this->db = new Database;
  10.     }
  11.  
  12.     public function checkLogin($data)
  13.     {
  14.         $username = htmlspecialchars($data['username']);
  15.         $password = htmlspecialchars($data['password']);
  16.  
  17.         $query = "SELECT * FROM {$this->db_table} WHERE username = :username";
  18.         $this->db->query($query);
  19.         $this->db->bind('username', $username);
  20.  
  21.         $row = $this->db->result();
  22.  
  23.         if (!empty($row)) {
  24.             if (password_verify($password, $row['password'])) {
  25.                 $_SESSION['login'] = true;
  26.  
  27.                 if (isset($data['remember'])) {
  28.                     setcookie('id', '12345', strtotime("+30 days"));
  29.                     var_dump($_COOKIE['id']); die;
  30.                 }
  31.  
  32.                 header("Location: ". BASEURL ."/mahasiswa");
  33.                 exit;
  34.             } else {
  35.                 Flasher::setFlash('password anda', 'salah', 'danger');
  36.                 header('Location: '. BASEURL .'/login');
  37.                 exit;
  38.             }
  39.         } else {
  40.             Flasher::setFlash('username anda', 'salah', 'danger');
  41.             header('Location: '. BASEURL .'/login');
  42.             exit;
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement