Guest User

Untitled

a guest
Jan 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. <?php
  2. /**
  3.  * User model for admin control & B2E
  4.  *
  5.  * @author Thalasseo
  6.  */
  7. class User extends CI_Model {
  8.    
  9.     protected $CI;
  10.    
  11.     protected $user;
  12.    
  13.     function __construct() {
  14.        
  15.         $this->CI = & get_instance();
  16.         $this->CI->load->library('encrypt');
  17.         $this->CI->load->library('session');
  18.         parent::__construct();
  19.     }
  20.    
  21.     /**
  22.      * Get username & check if password given is the same as encoded in db
  23.      * @param string $username
  24.      * @param string $password
  25.      * @return boolean
  26.      */
  27.     private function _check_password($username , $password , $encrypted = FALSE) {
  28.         $user = Orm_UserQuery::create()->findOneByUserName($username);
  29.         if ($user) {
  30.             if (!$encrypted) {
  31.                 $password = sha1(md5($password));
  32.             }
  33.             if ($user->getUserPassword() == $password) {
  34.                 return true;
  35.             }
  36.         }
  37.         return false;
  38.     }
  39.    
  40.     /**
  41.      * Log in username and store date in session
  42.      * @param string $username
  43.      * @param string $password
  44.      * @return boolean
  45.      */
  46.     public function login($username , $password) {
  47.         if ($this->_check_password($username , $password)) {
  48.            
  49.             /*$userdatas = $this->CI->encrypt->encode(serialize(array('username'=>$username , 'password'=>$password)));
  50.            
  51.             $this->CI->session->set_userdata($userdatas);*/
  52.            
  53.             echo 'Logged in';
  54.             return true;
  55.         } else {
  56.             echo 'Error while login';
  57.             return false;
  58.         }
  59.     }
  60.    
  61. }
  62.  
  63. ?>
Add Comment
Please, Sign In to add comment