Пример #1
0
 public function beforeFilter()
 {
     if ($this->request->is('ajax')) {
         $this->response->type("application/json");
         $this->layout = "ajax";
     } elseif ($this->request->params['controller'] != 'installers' && !$this->__isInstalled()) {
         $this->redirect(array('controller' => 'installers', 'action' => 'index'));
     } elseif ($this->request->params['controller'] == 'installers' && $this->__isInstalled()) {
         $this->Session->setFlash(__('Sonerezh is already installed. Remove or rename app/Config/database.php to run the installation again.'), 'flash_info');
         $this->redirect(array('controller' => 'songs', 'action' => 'index'));
     }
     if ($this->__isInstalled() && !$this->Auth->user() && $this->Cookie->check('auth')) {
         $this->loadModel('User');
         $cookie = $this->Cookie->read('auth');
         $authCookie = explode(':', $cookie);
         $user = $this->User->find('first', array('conditions' => array('id' => $authCookie[0])));
         $passwordHasher = new BlowfishPasswordHasher();
         if ($passwordHasher->check($user['User']['email'], $authCookie[1]) && $passwordHasher->check($user['User']['password'], $authCookie[2])) {
             unset($user['User']['password']);
             $this->Auth->login($user['User']);
             $this->Cookie->write('auth', $this->Cookie->read('auth'));
         } else {
             $this->Cookie->delete('auth');
         }
     }
     if (!$this->request->is('ajax') && $this->Auth->user()) {
         $this->loadModel('Setting');
         $setting = $this->Setting->find('first', array('fields' => array('sync_token')));
         $this->set('sync_token', $setting['Setting']['sync_token']);
     }
     $this->__setLanguage();
 }
Пример #2
0
 public function comparePassword($id = null, $password = null)
 {
     $passwordHasher = new BlowfishPasswordHasher();
     $this->id = $id;
     $hashPasswordData = $this->field('password');
     return $passwordHasher->check($password, $hashPasswordData);
 }
Пример #3
0
 public function checkCurrentPassword($current_password)
 {
     $this->id = AuthComponent::user('id');
     $saved_password = $this->field('password');
     $hasher = new BlowfishPasswordHasher();
     return $hasher->check($current_password, $saved_password);
 }
Пример #4
0
 public function login($user, $pass)
 {
     $passwordHasher = new BlowfishPasswordHasher();
     $x = $this->find('first', array('conditions' => array('User.email' => $user)));
     //debug($x);
     //exit;
     if (!empty($x)) {
         return $passwordHasher->check($pass, $x['User']['clave']);
     } else {
         return false;
     }
 }
Пример #5
0
 /**
  * Function to check the users old password is correct
  *
  * @param array $data The users data
  * @return booleen true is it matches, false otherwise
  */
 public function checkPassword($check)
 {
     $value = array_shift($check);
     if (strlen($value) == 0) {
         return true;
     }
     // if no userId is set
     if (empty($this->data['User']['id'])) {
         return false;
     }
     $this->contain();
     $user = $this->findById($this->data['User']['id'], 'password');
     if (!$user) {
         return false;
     }
     $passwordHasher = new BlowfishPasswordHasher();
     return $passwordHasher->check($value, $user['User']['password']);
 }
Пример #6
0
 /**
  * 現在のパスワードと確認パスワードが一致するかを判定する
  *
  * @return boolean
  */
 public function checkPassword()
 {
     $passwordHasher = new BlowfishPasswordHasher();
     $current_pass = $this->User->getPasswordById($this->Auth->user('id'));
     // パスワードの正誤判定
     if ($passwordHasher->check($this->request->data['User']['old_password'], $current_pass)) {
         return true;
     } else {
         return false;
     }
 }
Пример #7
0
 /**
  * Validation rule
  * Check value is equal current password
  * @author thientd
  */
 public function matchCurrentPassword($check)
 {
     $check = array_values($check);
     $check = $check[0];
     if (!$check) {
         return empty($this->data[$this->name]['password']);
     }
     if (empty($this->id)) {
         return false;
     }
     $user = $this->find('first', array('fields' => array('password'), 'conditions' => array($this->primaryKey => $this->id), 'recursive' => -1));
     if (!$user) {
         return false;
     }
     App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
     $passwordHasher = new BlowfishPasswordHasher();
     return $passwordHasher->check($check, $user[$this->alias]['password']);
 }