Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1.     public function check($i,$password)
  2.     {
  3.         $valid = FALSE;
  4.        
  5.         // Get information about current user
  6.         if($i AND $password)
  7.         {
  8.             // Find by ID
  9.             if(preg_match('/^([0-9]+)$/',$i))
  10.             {
  11.                 $user = $this->table->select('*')
  12.                                     ->where('id','=',$i)
  13.                                     ->clause('AND')
  14.                                     ->where('password','=',$password)
  15.                                     ->limit(1)
  16.                                     ->execute();
  17.             }
  18.            
  19.             // Find by Username
  20.             elseif(preg_match('/^([\-_ a-z0-9]+)$/is',$i))
  21.             {
  22.                 $user = $this->table->select('*')
  23.                                     ->where('username','=',$i)
  24.                                     ->clause('AND')
  25.                                     ->where('password','=',$password)
  26.                                     ->limit(1)
  27.                                     ->execute();
  28.             }
  29.            
  30.             // Find by E-mail
  31.             else
  32.             {
  33.                 $user = $this->table->select('*')
  34.                                     ->where('email','=',$i)
  35.                                     ->clause('AND')
  36.                                     ->where('password','=',$password)
  37.                                     ->limit(1)
  38.                                     ->execute();
  39.             }
  40.            
  41.             // If valid login credentials
  42.             if(!empty($user[0]))
  43.             {
  44.                 // If not banned, mark as valid
  45.                 if($user[0]['type'] != 'banned')
  46.                 {
  47.                     $valid = TRUE;
  48.                 }
  49.             }
  50.         }
  51.        
  52.         return $valid;
  53.     }
  54.  
  55.  
  56.  
  57.  
  58.     public function login($i,$password)
  59.     {
  60.         $this->_valid = FALSE;
  61.        
  62.         // Try to log in
  63.         if($i AND $password)
  64.         {
  65.             $password = $this->hash($password);
  66.        
  67.             // Find by ID
  68.             if(preg_match('/^([0-9]+)$/',$i))
  69.             {
  70.                 $user = $this->table->select('*')
  71.                                     ->where('id','=',$i)
  72.                                     ->clause('AND')
  73.                                     ->where('password','=',$password)
  74.                                     ->limit(1)
  75.                                     ->execute();
  76.             }
  77.            
  78.             // Find by Username
  79.             elseif(preg_match('/^([\-_ a-z0-9]+)$/is',$i))
  80.             {
  81.                 $user = $this->table->select('*')
  82.                                     ->where('username','=',$i)
  83.                                     ->clause('AND')
  84.                                     ->where('password','=',$password)
  85.                                     ->limit(1)
  86.                                     ->execute();
  87.             }
  88.            
  89.             // Find by E-mail
  90.             else
  91.             {
  92.                 $user = $this->table->select('*')
  93.                                     ->where('email','=',$i)
  94.                                     ->clause('AND')
  95.                                     ->where('password','=',$password)
  96.                                     ->limit(1)
  97.                                     ->execute();
  98.             }
  99.            
  100.             // If valid login credentials
  101.             if(!empty($user[0]))
  102.             {
  103.                 $user = $user[0];
  104.                 $this->_id = $user['id'];
  105.                 $this->_email = $user['email'];
  106.                 $this->_username = $user['username'];
  107.                 $this->_password = $user['password'];
  108.                 $this->_type = $user['type'];
  109.                 $this->_data = $user['data'];
  110.                
  111.                 // If not banned, mark as valid
  112.                 if($this->_type != 'banned')
  113.                 {
  114.                     $this->_valid = TRUE;
  115.                     $this->dingo->session->set('user_email',$this->_email);
  116.                     $this->dingo->session->set('user_password',$this->_password);
  117.                 }
  118.             }
  119.            
  120.             return $this->_valid;
  121.         }
  122.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement