Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function check($i,$password)
- {
- $valid = FALSE;
- // Get information about current user
- if($i AND $password)
- {
- // Find by ID
- if(preg_match('/^([0-9]+)$/',$i))
- {
- $user = $this->table->select('*')
- ->where('id','=',$i)
- ->clause('AND')
- ->where('password','=',$password)
- ->limit(1)
- ->execute();
- }
- // Find by Username
- elseif(preg_match('/^([\-_ a-z0-9]+)$/is',$i))
- {
- $user = $this->table->select('*')
- ->where('username','=',$i)
- ->clause('AND')
- ->where('password','=',$password)
- ->limit(1)
- ->execute();
- }
- // Find by E-mail
- else
- {
- $user = $this->table->select('*')
- ->where('email','=',$i)
- ->clause('AND')
- ->where('password','=',$password)
- ->limit(1)
- ->execute();
- }
- // If valid login credentials
- if(!empty($user[0]))
- {
- // If not banned, mark as valid
- if($user[0]['type'] != 'banned')
- {
- $valid = TRUE;
- }
- }
- }
- return $valid;
- }
- public function login($i,$password)
- {
- $this->_valid = FALSE;
- // Try to log in
- if($i AND $password)
- {
- $password = $this->hash($password);
- // Find by ID
- if(preg_match('/^([0-9]+)$/',$i))
- {
- $user = $this->table->select('*')
- ->where('id','=',$i)
- ->clause('AND')
- ->where('password','=',$password)
- ->limit(1)
- ->execute();
- }
- // Find by Username
- elseif(preg_match('/^([\-_ a-z0-9]+)$/is',$i))
- {
- $user = $this->table->select('*')
- ->where('username','=',$i)
- ->clause('AND')
- ->where('password','=',$password)
- ->limit(1)
- ->execute();
- }
- // Find by E-mail
- else
- {
- $user = $this->table->select('*')
- ->where('email','=',$i)
- ->clause('AND')
- ->where('password','=',$password)
- ->limit(1)
- ->execute();
- }
- // If valid login credentials
- if(!empty($user[0]))
- {
- $user = $user[0];
- $this->_id = $user['id'];
- $this->_email = $user['email'];
- $this->_username = $user['username'];
- $this->_password = $user['password'];
- $this->_type = $user['type'];
- $this->_data = $user['data'];
- // If not banned, mark as valid
- if($this->_type != 'banned')
- {
- $this->_valid = TRUE;
- $this->dingo->session->set('user_email',$this->_email);
- $this->dingo->session->set('user_password',$this->_password);
- }
- }
- return $this->_valid;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement