function authsomeLogin($type, $credentials = array()) { switch ($type) { case 'guest': // You can return any non-null value here, if you don't // have a guest account, just return an empty array return array(); case 'credentials': $password = Authsome::hash($credentials['password'], Configure::read('SparkPlug.hash.method'), Configure::read('SparkPlug.hash.salt')); // This is the logic for validating the login $conditions = array('User.username' => $credentials['username'], 'User.password' => $password, 'User.active' => '1'); break; case 'cookie': list($token, $userId) = split(':', $credentials['token']); $duration = $credentials['duration']; $loginToken = $this->LoginToken->find('first', array('conditions' => array('user_id' => $userId, 'token' => $token, 'duration' => $duration, 'used' => false, 'expires <=' => date('Y-m-d H:i:s', strtotime($duration))), 'contain' => false)); if (!$loginToken) { return false; } $loginToken['LoginToken']['used'] = true; $this->LoginToken->save($loginToken); $conditions = array('User.id' => $loginToken['LoginToken']['user_id']); break; default: return null; } return $this->find('first', compact('conditions')); }
public function beforeSave($options = array()) { # code... if (empty($this->data[$this->alias]['id'])) { //INSERT $this->data[$this->alias]['status'] = Configure::Read('STATUS.INITIAL'); if (isset($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = Authsome::hash($this->data[$this->alias]['password']); } } return true; }
public function authsomeLogin($type, $credentials = array()) { switch ($type) { case 'guest': // You can return any non-null value here, if you don't // have a guest account, just return an empty array return ""; case 'credentials': $password = Authsome::hash($credentials['password']); // This is the logic for validating the login $conditions = array('User.username' => $credentials['username'], 'User.password' => $password, 'User.rol != ' => Configure::read('ROL.PERSON')); break; default: return null; } return $this->find('first', compact('conditions')); }
function activatePassword($Model, $data) { $user = $Model->read(null, $data['User']['ident']); if ($user) { $password = $user['User']['password']; $salt = Configure::read("Security.salt"); $thekey = md5($password . $salt); if ($thekey == $data['User']['activate']) { $user['User']['password'] = $data['User']['password']; $user['User']['confirm_password'] = $data['User']['confirm_password']; if ($Model->save($user)) { $Model->updateAll(array('password' => "'" . Authsome::hash($user['User']['password'], Configure::read('SparkPlug.hash.method'), Configure::read('SparkPlug.hash.salt')) . "'"), "User.id = '" . $data['User']['ident'] . "'"); return true; } else { return false; } } else { return false; } } else { return false; } }
public function hash($password) { return Authsome::hash($password); }
public function login_person() { $data = $this->request->input('json_decode', true); $message = array('message' => 'Error revise sus datos.', 'code' => 400); if ($this->User->hasAny(array('User.username' => $data['username'], 'User.password' => Authsome::hash($data['password']), 'User.status' => Configure::Read('STATUS.INITIAL'), 'User.rol' => Configure::Read('ROL.PERSON')))) { $this->User->recursive = -1; $user = $this->User->find('first', array('conditions' => array('User.username' => $data['username'], 'User.password' => Authsome::hash($data['password'])))); $user = $user['User']['id']; $this->Person->recursive = -1; $person = $this->Person->findByUserId($user); $message['message'] = $person['Person']['identification'] . '_' . Configure::Read('ROL.PERSON'); $message['code'] = 200; } else { if ($this->User->hasAny(array('User.username' => $data['username'], 'User.password' => Authsome::hash($data['password']), 'User.status' => Configure::Read('STATUS.INITIAL'), 'User.rol' => Configure::Read('ROL.CHIEF')))) { $this->User->recursive = -1; $user = $this->User->find('first', array('conditions' => array('User.username' => $data['username'], 'User.password' => Authsome::hash($data['password'])))); $user = $user['User']['id']; $this->Chief->recursive = -1; $chief = $this->Chief->findByUserId($user); $message['message'] = $chief['Chief']['identification'] . '_' . Configure::Read('ROL.CHIEF'); $message['code'] = 200; } } $this->set(array('Message' => $message, '_serialize' => array('Message'))); }
public function updatePassword($data = array()) { if (empty($data[$this->alias]['new_password'])) { return false; } if (empty($data[$this->alias]['confirm_password'])) { return false; } $this->set(array('new_password' => $data[$this->alias]['new_password'], 'confirm_password' => $data[$this->alias]['confirm_password'])); if (!$this->validates()) { return false; } $this->create(array('password' => Authsome::hash($data[$this->alias]['new_password']))); $this->id = Authsome::get('id'); return $this->save(); }
public function isCorrectPassword() { $user = $this->data['User']; return $this->find('first', array( 'conditions' => array( 'User.id' => $user['id'], 'User.password' => Authsome::hash($user['current_password']) ) )); }
function authsomeLogin($type, $credentials = array()) { switch ($type) { case 'guest': // You can return any non-null value here, if you don't // have a guest account, just return an empty array return array('guest' => 'guest'); case 'credentials': // This is the logic for validating the login $conditions = array("{$this->alias}.email" => $credentials['login'], "{$this->alias}.password" => Authsome::hash($credentials['password'])); break; case 'username': $conditions = array("{$this->alias}.{$this->displayField}" => $credentials['login'], "{$this->alias}.password" => Authsome::hash($credentials['password'])); break; case 'cookie': list($token, $maintainerId) = split(':', $credentials['token']); $duration = $credentials['duration']; $loginToken = $this->LoginToken->find('first', array('conditions' => array('user_id' => $maintainerId, 'token' => $token, 'duration' => $duration, 'used' => false, 'expires <=' => date('Y-m-d H:i:s', strtotime($duration))), 'contain' => false)); if (!$loginToken) { return false; } $loginToken['LoginToken']['used'] = true; $this->LoginToken->save($loginToken); $conditions = array("{$this->alias}.{$this->primaryKey}" => $loginToken['LoginToken']['user_id']); break; default: return null; } $maintainer = $this->find('first', compact('conditions')); if (!$maintainer) { return false; } $maintainer[$this->alias]['loginType'] = $type; return $maintainer; }