Advertisement
Guest User

Untitled

a guest
Oct 29th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. class Login_Model extends Model
  2. {
  3.  
  4.     public function __construct()
  5.     {
  6.         parent::__construct();
  7.     }
  8.  
  9.     public function run()
  10.     {
  11.             $sth = $this->db->prepare("SELECT userid, role FROM user WHERE login = :login AND password = :password");
  12.             $sth->execute(array(
  13.                 ':login'    => $_POST['login'],
  14.                 ':password' => Hash::create('sha256', $_POST['password'], HASH_PASSWORD_KEY)
  15.             ));
  16.  
  17.             $data  = $sth->fetch();
  18.  
  19.  
  20.             $count =  $sth->rowCount();
  21.  
  22.  
  23.         if($count > 0 ){
  24.             //login
  25.             Session::init();
  26.             Session::set('role', $data['role']);
  27.             Session::set('loggedIn', true);
  28.             Session::set('userid', $data['userid']);
  29.             header('location: ../dashboard');
  30.  
  31.         } else {
  32.  
  33.                header('location: ../login');
  34.         }
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement