Esempio n. 1
0
 public function beforeSave($options = array())
 {
     // hash the password
     if (isset($this->data[$this->alias]['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     }
     // initially generate the url // generate default url if user_level_id is 10 or 20 in data
     if (isset($this->data[$this->alias]['email'])) {
         $this->data[$this->alias]['url'] = md5($this->data[$this->alias]['email']);
     } else {
         if (isset($this->data[$this->alias]['user_level_id']) && ($this->data[$this->alias]['user_level_id'] == 10 || $this->data[$this->alias]['user_level_id'] == 20)) {
             $this->data[$this->alias]['url'] = md5(AuthComponent::user('email'));
         }
     }
     //check if user has pre-url, prepend pre-url to url
     if (isset($this->data[$this->alias]['pre_url'])) {
         $this->data[$this->alias]['url'] = $this->data[$this->alias]['pre_url'] . "" . $this->data[$this->alias]['url'];
     }
     // check/set referral for user
     App::uses('CakeSession', 'Model/Datasource');
     $referral_id = CakeSession::read('referral');
     if (!empty($referral_id)) {
         $this->data[$this->alias]['referral_id'] = $referral_id;
         CakeSession::delete('referral');
     }
     return true;
 }
Esempio n. 2
0
 public function beforeSave($options = array())
 {
     $passwordHasher = new BlowfishPasswordHasher();
     $this->data['User']['password'] = $passwordHasher->hash($this->data['User']['password']);
     $this->log("beforesave" . $this->data['User']['password'], 'debug');
     return true;
 }
Esempio n. 3
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();
 }
Esempio n. 4
0
 public function comparePassword($id = null, $password = null)
 {
     $passwordHasher = new BlowfishPasswordHasher();
     $this->id = $id;
     $hashPasswordData = $this->field('password');
     return $passwordHasher->check($password, $hashPasswordData);
 }
 public function add_api()
 {
     if ($this->request->is(array('post', 'xml')) && $this->request->data['Trade']['product_id'] > 0 && $this->request->data['Trade']['user_id'] > 0) {
         $this->Trade->create();
         $this->request->data['Trade']['validated'] = 0;
         $this->Trade->Product->id = $this->request->data['Trade']['product_id'];
         $this->Trade->User->id = $this->request->data['Trade']['user_id'];
         $cost = $this->Trade->Product->field('points_value');
         $user_total = $this->Trade->User->field('total_points');
         $available = $this->Trade->Product->field('quantity_available');
         if ($user_total > $cost && $this->Trade->save($this->request->data) && $available > 0) {
             $this->Trade->User->saveField('total_points', $user_total - $cost);
             $this->Trade->Product->saveField('quantity_available', $this->Trade->Product->field('quantity_available') - 1);
             $qrCode = $this->Trade->id . $this->request->data['Trade']['user_id'] . $this->request->data['Trade']['product_id'] . $this->Trade->field('created');
             $passwordHasher = new BlowfishPasswordHasher();
             $qrCode = $passwordHasher->hash($qrCode);
             $this->Trade->saveField('qr_code', $qrCode);
             $message = array(__('The trade has been saved.'));
             $general_response = array('data' => $qrCode, 'status' => 'success', 'message' => $message);
         } else {
             $message = array(__('The trade could not be saved. Please, try again.'));
             $general_response = array('data' => null, 'status' => 'failure', 'message' => $message);
         }
         $this->set(array('general_response' => $general_response, '_serialize' => array('general_response')));
     }
 }
Esempio n. 6
0
 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->alias]['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     }
 }
Esempio n. 7
0
 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->alias]['password'])) {
         $passwordHasher = new BlowfishPasswordHasher(array('hashType' => 'md5'));
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     }
     return true;
 }
Esempio n. 8
0
 public function beforeSave($options = array())
 {
     if (isset($this->data['User']['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data['User']['password'] = $passwordHasher->hash($this->data['User']['password']);
     }
     return true;
 }
Esempio n. 9
0
 /**
  * beforeSave function
  * @return bool
  */
 public function beforeSave()
 {
     if (isset($this->data[$this->alias]['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     }
     return true;
 }
Esempio n. 10
0
 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->alias]['clave_de_acceso'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['clave_de_acceso'] = $passwordHasher->hash($this->data[$this->alias]['clave_de_acceso']);
     }
     return true;
 }
Esempio n. 11
0
 public function beforeSave($options = [])
 {
     //パスワードのハッシュ化のため
     if (isset($this->data[$this->alias]['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     }
     return true;
 }
Esempio n. 12
0
 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->alias]['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     }
     $this->data[$this->alias]['dataEntrada'] = Date('c');
     return true;
 }
Esempio n. 13
0
 public function beforeSave($options = array())
 {
     if (!empty($this->data[$this->alias]['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     } else {
         unset($this->data[$this->alias]['password']);
     }
     return true;
 }
Esempio n. 14
0
 public function beforeSave($options = array())
 {
     if (isset($this->data[$this->alias]['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     }
     if (isset($this->data[$this->alias]['avatar']) && is_array($this->data[$this->alias]['avatar'])) {
         $this->__uploadAvatar($this->data[$this->alias]['avatar']);
     }
     return true;
 }
Esempio n. 15
0
 public function after($event = array())
 {
     if (isset($event['create'])) {
         $table = $event['create'];
         $data = null;
         switch ($table) {
             case 'base_types':
                 $data = array(array('name' => __('Beef')), array('name' => __('Bread')), array('name' => __('Egg')), array('name' => __('Fruit')), array('name' => __('Grain')), array('name' => __('Lamb')), array('name' => __('Other')), array('name' => __('Pasta')), array('name' => __('Pork/Ham')), array('name' => __('Poultry')), array('name' => __('Seafood')), array('name' => __('Vegetable')));
                 break;
             case 'courses':
                 $data = array(array('name' => __('Breakfast')), array('name' => __('Snack')), array('name' => __('Lunch')), array('name' => __('Appetizer')), array('name' => __('Side Dish')), array('name' => __('Entree')), array('name' => __('Dessert')), array('name' => __('Beverage')));
                 break;
             case 'difficulties':
                 $data = array(array('name' => __('Easy')), array('name' => __('Intermediate')), array('name' => __('Difficult')), array('name' => __('Expert')));
                 break;
             case 'ethnicities':
                 $data = array(array('name' => __('American')), array('name' => __('Chinese')), array('name' => __('German')), array('name' => __('Greek')), array('name' => __('Indian')), array('name' => __('Italian')), array('name' => __('Japanese')), array('name' => __('Mexican')), array('name' => __('Middle Eastern')), array('name' => __('None')), array('name' => __('Slavic')));
                 break;
             case 'locations':
                 $data = array(array('name' => __('Alcohol')), array('name' => __('Bakery')), array('name' => __('Beans')), array('name' => __('Bread')), array('name' => __('Candy')), array('name' => __('Canned Fruit')), array('name' => __('Canned Meat & Fish')), array('name' => __('Canned Vegetables')), array('name' => __('Coffee, Tea & Cocoa')), array('name' => __('Condiments')), array('name' => __('Cookies')), array('name' => __('Crackers')), array('name' => __('Dairy')), array('name' => __('Deli')), array('name' => __('Drink mix')), array('name' => __('Facial Tissue')), array('name' => __('Free')), array('name' => __('Frozen Foods')), array('name' => __('HABA')), array('name' => __('Hand Soap')), array('name' => __('Hot & Cold Cereal')), array('name' => __('Household Cleaners')), array('name' => __('Juice & Cocktail')), array('name' => __('Kosher/Ethnic')), array('name' => __('Laundry Detergents')), array('name' => __('Meat')), array('name' => __('Natural & Organic')), array('name' => __('Oil/Vinegar/Dressings')), array('name' => __('Pancakes & Syrup')), array('name' => __('Paper Serving Ware')), array('name' => __('Pasta & Sauce')), array('name' => __('Peanut Butter/Jelly/Honey')), array('name' => __('Produce')), array('name' => __('Rice')), array('name' => __('Salty Snacks & Chips')), array('name' => __('Seafood')), array('name' => __('Soda pop')), array('name' => __('Soup')), array('name' => __('Spices')), array('name' => __('Toilet Paper')));
                 break;
             case 'meal_names':
                 $data = array(array('name' => __('Breakfast')), array('name' => __('Lunch')), array('name' => __('Dinner')), array('name' => __('Dessert')));
                 break;
             case 'preparation_methods':
                 $data = array(array('name' => __('Slow cooker')), array('name' => __('Microwave')), array('name' => __('BBQ')), array('name' => __('Canning')));
                 break;
             case 'preparation_times':
                 $data = array(array('name' => __('0 Minutes')), array('name' => __('1-10 Minutes')), array('name' => __('10-30 Minutes')), array('name' => __('30-60 Minutes')), array('name' => __('60+ Minutes')));
                 break;
             case 'price_ranges':
                 $data = array(array('name' => __('$0-$10')), array('name' => __('$10-$15')), array('name' => __('$15-$20')), array('name' => __('$20-$25')), array('name' => __('$25-$30')), array('name' => __('$30+')));
                 break;
             case 'stores':
                 $data = array(array('name' => 'default', 'layout' => '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40'));
                 break;
             case 'units':
                 $data = array(array('id' => 1, 'name' => __('Unit'), 'abbreviation' => 'ea', 'system' => 0, 'sort_order' => 0), array('id' => 2, 'name' => __('Slice'), 'abbreviation' => 'sli', 'system' => 0, 'sort_order' => 0), array('id' => 3, 'name' => __('Clove'), 'abbreviation' => 'clv', 'system' => 0, 'sort_order' => 0), array('id' => 4, 'name' => __('Pinch'), 'abbreviation' => 'pn', 'system' => 0, 'sort_order' => 0), array('id' => 5, 'name' => __('Package'), 'abbreviation' => 'pk', 'system' => 0, 'sort_order' => 0), array('id' => 6, 'name' => __('Can'), 'abbreviation' => 'cn', 'system' => 0, 'sort_order' => 0), array('id' => 7, 'name' => __('Drop'), 'abbreviation' => 'dr', 'system' => 0, 'sort_order' => 0), array('id' => 8, 'name' => __('Bunch'), 'abbreviation' => 'bn', 'system' => 0, 'sort_order' => 0), array('id' => 9, 'name' => __('Dash'), 'abbreviation' => 'ds', 'system' => 0, 'sort_order' => 0), array('id' => 10, 'name' => __('Carton'), 'abbreviation' => 'ct', 'system' => 0, 'sort_order' => 0), array('id' => 11, 'name' => __('Cup'), 'abbreviation' => 'c', 'system' => 1, 'sort_order' => 0), array('id' => 12, 'name' => __('Tablespoon'), 'abbreviation' => 'T', 'system' => 1, 'sort_order' => 0), array('id' => 13, 'name' => __('Teaspoon'), 'abbreviation' => 't', 'system' => 1, 'sort_order' => 0), array('id' => 14, 'name' => __('Pound'), 'abbreviation' => 'lb', 'system' => 1, 'sort_order' => 0), array('id' => 15, 'name' => __('Ounce'), 'abbreviation' => 'oz', 'system' => 1, 'sort_order' => 0), array('id' => 16, 'name' => __('Pint'), 'abbreviation' => 'pt', 'system' => 1, 'sort_order' => 0), array('id' => 17, 'name' => __('Quart'), 'abbreviation' => 'q', 'system' => 1, 'sort_order' => 0), array('id' => 18, 'name' => __('Gallon'), 'abbreviation' => 'gal', 'system' => 1, 'sort_order' => 0), array('id' => 19, 'name' => __('Milligram'), 'abbreviation' => 'mg', 'system' => 2, 'sort_order' => 0), array('id' => 20, 'name' => __('Centigram'), 'abbreviation' => 'cg', 'system' => 2, 'sort_order' => 0), array('id' => 21, 'name' => __('Gram'), 'abbreviation' => 'g', 'system' => 2, 'sort_order' => 0), array('id' => 22, 'name' => __('Kilogram'), 'abbreviation' => 'kg', 'system' => 2, 'sort_order' => 0), array('id' => 23, 'name' => __('Milliliter'), 'abbreviation' => 'ml', 'system' => 2, 'sort_order' => 0), array('id' => 24, 'name' => __('Centiliter'), 'abbreviation' => 'cl', 'system' => 2, 'sort_order' => 0), array('id' => 25, 'name' => __('Liter'), 'abbreviation' => 'l', 'system' => 2, 'sort_order' => 0), array('id' => 26, 'name' => __('Deciliter'), 'abbreviation' => 'dl', 'system' => 2, 'sort_order' => 0), array('id' => 27, 'name' => __('Tablespoon_m'), 'abbreviation' => 'tbsp', 'system' => 2, 'sort_order' => 0), array('id' => 28, 'name' => __('Teaspoon_m'), 'abbreviation' => 'tsp', 'system' => 2, 'sort_order' => 0));
                 break;
             case 'users':
                 $passwordHasher = new BlowfishPasswordHasher();
                 $data = array(array('username' => 'admin', 'password' => $passwordHasher->hash('passwd'), 'name' => 'Administrator', 'access_level' => Configure::read('AuthRoles.admin'), 'email' => 'user@localhost'));
                 break;
             case 'vendors':
                 $data = array(array('name' => 'Presto Fresh Grocery', 'home_url' => 'http://www.prestofreshgrocery.com/', 'add_url' => 'http://www.prestofreshgrocery.com/checkout/cart/add/uenc/a/product/'));
                 break;
             default:
         }
         if ($data) {
             ClassRegistry::init($table)->saveAll($data);
         }
     }
 }
Esempio n. 16
0
 public function beforeSave($options = array())
 {
     // a file has been uploaded so grab the filepath
     if (!empty($this->data[$this->alias]['avatar'])) {
         $this->data[$this->alias]['avatar'] = $this->data[$this->alias]['avatar'];
     }
     if (isset($this->data[$this->alias]['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     }
     return parent::beforeSave($options);
 }
Esempio n. 17
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;
     }
 }
Esempio n. 18
0
 public function hash()
 {
     if ($this->request->is('post')) {
         $user['username'] = $this->request->data['Page']['username'];
         if (isset($this->request->data['Page']['password'])) {
             App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
             $passwordHasher = new BlowfishPasswordHasher();
             $user['password'] = $passwordHasher->hash($this->request->data['Page']['password']);
         }
         $this->set('user', $user);
     }
     $this->set(array('title_for_layout' => __('Generate Hash') . ' - One Day, One Picture'));
 }
Esempio n. 19
0
 /**
  * Before Save
  * @param array $options
  * @return boolean
  */
 public function beforeSave($options = array())
 {
     // hash the user's password befor we save it
     if (isset($this->data[$this->alias]['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     }
     // if we get an updated password, hash it
     if (isset($this->data[$this->alias]['password_update'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password_update']);
     }
     // fallback to our parent
     return parent::beforeSave($options);
 }
Esempio n. 20
0
 public function signUp()
 {
     $data = $this->request->data;
     if (isset($data['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $data['password'] = $passwordHasher->hash($data['password']);
     }
     $res = $this->User->save($data);
     if ($res) {
         unset($res['User']['password']);
         $res['message'] = "登録しました。ログインできます。";
     } else {
         $res['message'] = "登録に失敗しました!";
     }
     $this->set(compact('res'));
     $this->set('_serialize', 'res');
 }
Esempio n. 21
0
 public function signUp()
 {
     $data = $this->request->data;
     if (isset($data['password'])) {
         $passwordHasher = new BlowfishPasswordHasher();
         $data['password'] = $passwordHasher->hash($data['password']);
     }
     $res = $this->User->save($data);
     if ($res) {
         unset($res['User']['password']);
         $res['message'] = "Register successfully, you can Login!";
     } else {
         $res['message'] = "Fail to register";
         //  $res['message'] = json_encode($data);
     }
     $this->set(compact('res'));
     $this->set('_serialize', 'res');
 }
Esempio n. 22
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']);
 }
Esempio n. 23
0
 /**
  * add method
  *
  * @return void
  */
 public function add()
 {
     if ($this->request->is('post')) {
         $d = $this->request->data;
         $this->User->create();
         if ($this->User->save($this->request->data)) {
             $passwordHasher = new BlowfishPasswordHasher();
             $link = array('controller' => 'users', 'action' => 'activate', $this->User->id . '-' . $passwordHasher->hash($d['User']['password']));
             App::uses('CakeEmail', 'Network/Email');
             $mail = new CakeEmail('gmail');
             $mail->from('*****@*****.**')->to($d['User']['email'])->subject('Test :: Inscription')->emailFormat('html')->template('signup')->viewVars(array('username' => $d['User']['username'], 'link' => $link))->send();
             $this->Session->setFlash(__('A mail has been sent'), 'flash/success');
             $this->redirect(array('action' => 'index'));
         } else {
             $this->Session->setFlash(__('The user could not be saved. Please, try again.'), 'flash/error');
         }
     }
     $collections = $this->User->Collection->find('list');
     $this->set(compact('collections'));
 }
Esempio n. 24
0
 public function beforeSave($options = array())
 {
     // Si existe un id de 'User' significa que estamos editando el registro.
     if (!empty($this->data[$this->alias]['id'])) {
         // Si el password de 'User' es enviado como vacio, significa que no se está modificando.
         if (empty($this->data[$this->alias]['password'])) {
             // Recuperamos el password actual de 'User'
             $pass = $this->find('first', ['conditions' => ['id' => $this->data[$this->alias]['id']]]);
             $this->data[$this->alias]['password'] = $pass['User']['password'];
         } else {
             // De no ser asi encriptamos el nuevo password de 'User'
             $passwordHasher = new BlowfishPasswordHasher();
             $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
         }
     } elseif (isset($this->data[$this->alias]['password'])) {
         // De no ser asi estamos creando un nuevo 'User', entonces encriptamos el password
         $passwordHasher = new BlowfishPasswordHasher();
         $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
     }
     return true;
 }
 function editMember()
 {
     $this->layout = false;
     $this->autoRender = false;
     if (empty($this->request->data)) {
         $response['success'] = false;
         $response['message'] = 'Empty data sent!';
         return json_encode($response);
     }
     $saveData['User']['id'] = $this->request->data['User_id'];
     $saveData['User']['name'] = trim($this->request->data['User_name']);
     $saveData['User']['surname'] = trim($this->request->data['User_surname']);
     $saveData['User']['mail'] = trim($this->request->data['User_mail']);
     $saveData['User']['username'] = trim($this->request->data['User_mail']);
     $saveData['User']['oib'] = trim($this->request->data['User_oib']);
     $saveData['User']['address'] = trim($this->request->data('User_address'));
     $saveData['User']['phone'] = trim($this->request->data('User_phone'));
     $saveData['User']['active'] = trim($this->request->data('User_active'));
     if (!empty($this->request->data['User_password'])) {
         App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
         $passwordHasher = new BlowfishPasswordHasher();
         $saveData['User']['password'] = $passwordHasher->hash($this->request->data['User_password']);
     }
     if ($this->User->saveAll($saveData)) {
         $response['success'] = true;
         $response['message'] = __('User successfully saved.');
     } else {
         $response['success'] = false;
         $response['message'] = __('Error while saving. Please contact your Administrator.');
     }
     return json_encode($response);
 }
Esempio n. 26
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']);
 }
Esempio n. 27
0
 public function login()
 {
     $this->layout = 'login';
     $this->loadModel('Setting');
     $settings = $this->Setting->find('first', array('fields' => 'Setting.enable_mail_notification'));
     $this->set(compact('settings'));
     if ($this->request->is('post')) {
         if ($this->Auth->login()) {
             if ($this->request->data['User']['rememberme']) {
                 $user = $this->User->find('first', array('fields' => array('password'), 'conditions' => array('User.id' => $this->Auth->user('id'))));
                 $passwordHasher = new BlowfishPasswordHasher();
                 $this->Cookie->write('auth', $this->Auth->user('id') . ':' . $passwordHasher->hash($this->request->data['User']['email']) . ':' . $passwordHasher->hash($user['User']['password']));
             } else {
                 $this->Session->delete('auth');
             }
             return $this->redirect($this->Auth->redirectUrl());
         } else {
             $this->Flash->error(__('Wrong credentials!'));
         }
     }
 }
Esempio n. 28
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;
     }
 }
Esempio n. 29
0
 public function changePassword()
 {
     if ($this->request->is('post')) {
         if ($this->request->data['User']['newPassword'] == $this->request->data['User']['newPasswordRepeat']) {
             $passwordHasher = new BlowfishPasswordHasher();
             $user = $this->User->findById($this->Auth->user('id'));
             $user['User']['password'] = $passwordHasher->hash($this->request->data['User']['newPassword']);
             if ($this->User->save($user)) {
                 $this->Session->setFlash(__('Password changed.'), 'flashes/success');
                 return $this->redirect(array('action' => 'index'));
             } else {
                 $this->Session->setFlash(__('Error changing password.'));
                 return $this->redirect(array('action' => 'index'));
             }
         } else {
             $this->Session->setFlash(__('Passwords do not match.'));
             return $this->redirect(array('action' => 'changePassword'));
         }
     }
     $this->set('currentUsername', $this->Auth->user('username'));
 }
Esempio n. 30
0
 /**
  * Before Save filter method
  * This method hashes password or password_update before put into database
  *
  * @param array $options
  * @return bool
  */
 public function beforeSave($options = array())
 {
     //Initialize password hasher
     $pwHasher = new BlowfishPasswordHasher();
     //Hash password before put into db
     if (isset($this->data[$this->alias]['password'])) {
         $this->data[$this->alias]['password'] = $pwHasher->hash($this->data[$this->alias]['password']);
     }
     //Hash updated password as well
     if (isset($this->data[$this->alias]['password_update'])) {
         $this->data[$this->alias]['password'] = $pwHasher->hash($this->data[$this->alias]['password_update']);
     }
     return parent::beforeSave($options);
 }