Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function find($user = null) {
- if ($user) {
- $field = (is_numeric($user)) ? 'id' : 'username';
- $data = $this->_db->get('users', array($field, '=', $user));
- if ($data->count()) {
- $this->_data = $data->first();
- return true;
- }
- }
- return false;
- }
- public function login($username = null, $password = null, $remember = false) {
- if (!$username && !$password && $this->exists()) {
- Session::put($this->_sessionName, $this->data()->id);
- } else {
- $user = $this->find($username);
- if ($user) {
- if ($this->data()->password === Hash::make($password, $this->data()->salt)) {
- Session::put($this->_sessionName, $this->data()->id);
- if ($remember) {
- $hash = Hash::unique();
- $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id));
- if (!$hashCheck->count()) {
- $this->_db->insert('users_session', array(
- 'user_id' => $this->data()->id,
- 'hash' => $hash
- ));
- } else {
- $hash = $hashCheck->first()->hash;
- }
- Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry'));
- }
- return true;
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement