/**
  * Authentication
  * @return bool
  */
 public function authenticate()
 {
     /** @var AccountModule $account */
     $account = Yii::app()->getModule('account');
     /** @var AccountUser $user */
     $user = CActiveRecord::model($account->userClass)->find('(LOWER(username)=? OR LOWER(email)=?)', array(strtolower($this->username), strtolower($this->username)));
     if (!$user) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
         return false;
     }
     if ($account->activatedField && !$user->{$account->activatedField}) {
         $this->errorCode = self::ERROR_NOT_ACTIVATED;
         return false;
     }
     if ($account->disabledField && $user->{$account->disabledField}) {
         $this->errorCode = self::ERROR_DISABLED;
         return false;
     }
     if (!$this->skipPassword && !CPasswordHelper::verifyPassword($this->password, $user->{$account->passwordField})) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
         return false;
     }
     $this->_id = $user->primaryKey;
     $this->username = $account->usernameField && $user->{$account->usernameField} ? $user->{$account->usernameField} : $user->{$account->emailField};
     $this->errorCode = self::ERROR_NONE;
     return true;
 }
Exemplo n.º 2
0
 public function validatePassword($user)
 {
     if ($user->password) {
         return CPasswordHelper::verifyPassword($this->password, $user->password);
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Overrides the parent method.
  * 
  * @return integer Returns the error code.
  */
 public function authenticate()
 {
     $this->errorCode = self::ERROR_NONE;
     if (isset($this->username) && isset($this->password)) {
         $this->user = User::model()->findByAttributes(array('email' => $this->username));
         if (isset($this->user)) {
             if ($this->user->status == User::STATUS_ACTIVE) {
                 if (CPasswordHelper::verifyPassword($this->password, $this->user->password)) {
                     Yii::app()->user->login($this);
                     //TODO: write a log here
                 } else {
                     $this->errorCode = self::ERROR_PASSWORD_INVALID;
                     //TODO: write a log here
                 }
             } else {
                 $this->errorCode = self::ERROR_USERNAME_INACTIVE;
                 //TODO: write a log here
             }
         } else {
             $this->errorCode = self::ERROR_USERNAME_INVALID;
             //TODO: write a log here
         }
     }
     return $this->errorCode;
 }
Exemplo n.º 4
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Propietario();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Propietario'])) {
         $model->attributes = $_POST['Propietario'];
         $usuario = new Usuario();
         $model->rut = Tools::removeDots($model->rut);
         $usuario->user = $model->rut;
         $arr = explode("-", $model->rut);
         $usuario->clave = CPasswordHelper::hashPassword($arr[0]);
         $usuario->rol = "propietario";
         $usuario->nombre = $_POST['Propietario']['nombre'];
         $usuario->email = $_POST['Propietario']['email'];
         $usuario->apellido = $_POST['Propietario']['apellido'];
         $model->usuario_id = 1;
         if ($model->validate()) {
             if ($usuario->validate()) {
                 if ($usuario->save()) {
                     $model->usuario_id = $usuario->id;
                     if ($model->save()) {
                         $auth = Yii::app()->authManager;
                         Authassignment::model()->deleteAllByAttributes(array('userid' => $usuario->id));
                         $auth->revoke($usuario->rol, $model->usuario_id);
                         $auth->assign($usuario->rol, $model->usuario_id);
                         $this->redirect(array('view', 'id' => $model->id));
                     }
                 }
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 5
0
 protected function beforeSave()
 {
     if (isset($this->senha)) {
         $this->senha = CPasswordHelper::hashPassword($this->senha);
     }
     return parent::beforeSave();
 }
Exemplo n.º 6
0
 public function authenticate()
 {
     $record = User::model()->findByAttributes(array('username' => $this->username));
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!CPasswordHelper::verifyPassword($this->password, $record->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $access = AccessGlobal::getAction($record->role == 'superadmin' ? '0' : '1');
             if ($record->role == 'user') {
                 $access['site'] = array_intersect($access['site'], AccessGlobal::getActionFromArrayId(AccessUser::getActionIdFromUser($record->user_id)));
             }
             if ($record->role == 'admin') {
                 $access['site'] = array_intersect($access['site'], AccessGlobal::getActionFromArrayId(AccessUser::getActionIdFromUser($record->user_id)));
             }
             $this->_id = $record->user_id;
             $this->setState('role', $record->role);
             $this->setState('name', $this->username);
             $this->setState('access', $access);
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
Exemplo n.º 7
0
 public function createAdmin()
 {
     $attributes = array('username' => 'admin', 'email' => '*****@*****.**', 'password' => CPasswordHelper::hashPassword('iddqd3311'), 'email_verified' => 1);
     $user = new Users();
     $user->attributes = $attributes;
     $user->save();
 }
Exemplo n.º 8
0
 public function authenticate()
 {
     $user = User::model()->with('service')->find('username=:u', ['u' => $this->username]);
     $verifyPassword = false;
     if (empty($user)) {
         $state = 1;
     } else {
         $verifyPassword = CPasswordHelper::verifyPassword($this->password, $user->password);
         $state = $verifyPassword ? 0 : 1;
     }
     $result = Fraudmetrix::login($this->username, $state);
     if ($result['success'] == true && $result['final_decision'] == 'Reject') {
         $this->errorCode = self::ERROR_UNKNOWN_IDENTITY;
         $this->errorMessage = '未知错误';
     } else {
         if (empty($user)) {
             $this->errorCode = self::ERROR_USERNAME_INVALID;
             $this->errorMessage = '用户邮箱不存在';
         } else {
             if ($user->state == 1) {
                 $this->errorCode = self::ERROR_NOT_LOGIN;
                 $this->errorMessage = '登录账号已被锁定';
             } elseif (!$verifyPassword) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
                 $this->errorMessage = '用户密码错误';
             } else {
                 $server = Setting::model()->get('wakfu', 'server');
                 $this->errorCode = self::ERROR_NONE;
                 $this->setPersistentStates(array_merge($user->getAttributes(), ['last_login_time' => $user->last_login_time, 'last_login_ip' => $user->last_login_ip, 'sign_up_time' => $user->sign_up_time, 'sign_up_ip' => $user->sign_up_ip, 'server' => $server[$user->service->server], 'port' => $user->service->port]));
                 $this->afterLogin($user);
             }
         }
     }
     return !$this->errorCode;
 }
Exemplo n.º 9
0
 /**
  * 
  * @param unknown $attribute
  * @param unknown $params
  */
 public function checkOldPassword($attribute, $params)
 {
     $user = User::model()->findByAttributes(array('id' => Yii::app()->user->getId()));
     if (!empty($this->oldPassword) && !CPasswordHelper::verifyPassword($this->oldPassword, $user->password)) {
         $this->addError('oldPassword', Yii::t('ProfileModule.password', 'error.password.oldPasswordWrong'));
     }
 }
 public function actionRegister()
 {
     $username = $_POST['username'];
     $password = $_POST['password'];
     if (strlen($username) < 3) {
         Helper::renderJSONErorr("Username must be at least 3 symbols: {$username} [" . strlen($username) . "]");
     }
     if (strlen($password) < 5) {
         Helper::renderJSONErorr("Password must be at least 5 symbols");
     }
     // Check user
     $user = User::model()->find('username=:username', array(':username' => $username));
     if ($user) {
         Helper::renderJSONErorr("Username occupated");
     }
     // Create new user
     $model = new User();
     $model->username = $username;
     $model->password = CPasswordHelper::hashPassword($password);
     if ($model->save()) {
         Helper::renderJSON($model);
     }
     // Catch errors
     $errors = [];
     foreach ($model->errors as $attribute => $attr_errors) {
         foreach ($attr_errors as $attr_error) {
             $errors[] = "Attribute {$attribute}: {$attr_error}";
         }
     }
     Helper::renderJSONErorr(implode("\n", $errors));
 }
Exemplo n.º 11
0
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         if (!CPasswordHelper::verifyPassword($this->old_password, Yii::app()->user->user->password)) {
             $this->addError('old_password', Yii::t("app", "Le mot de passe actuel entré est incorrect."));
         }
     }
 }
Exemplo n.º 12
0
 public function __set($name, $value)
 {
     if ($name === 'password') {
         $value = CPasswordHelper::hashPassword($value);
     }
     parent::__set($name, $value);
     // TODO: Change the autogenerated stub
 }
Exemplo n.º 13
0
 /**
  *
  * 某些系统不支持crypt加密。只能用md5加密了
  *
  *
  * @param password        客户端传递过来的密码
  *@param array $params
  * @return string
  */
 public function hashPassword($password, array $params = array())
 {
     if (!function_exists('crypt')) {
         return CPasswordHelper::hashPassword($password);
     } else {
         return md5($password);
     }
 }
 /**
  * Updates the users password.
  * @param bool $runValidation
  */
 public function save($runValidation = true)
 {
     if ($runValidation && !$this->validate()) {
         return false;
     }
     /** @var AccountModule $account */
     $account = Yii::app()->getModule('account');
     $this->user->{$account->passwordField} = CPasswordHelper::hashPassword($this->new_password);
     return $this->user->save(false);
 }
Exemplo n.º 15
0
 public function compareOldPassword($attribute)
 {
     //return($old->password === Yii::app()->digester->md5($_password));
     $userlogin = User::model()->findByPk($this->id);
     if (CPasswordHelper::verifyPassword($this->{$attribute}, $userlogin->password)) {
         return TRUE;
     } else {
         $this->addError('oldpassword', 'Password Lama yang anda masukkan salah');
     }
 }
Exemplo n.º 16
0
 public function changePassword()
 {
     $user = Yii::app()->controller->user;
     $user->password = CPasswordHelper::hashPassword($this->newPassword);
     if ($user->save()) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 17
0
 /**
  * Este método se llama cuando inserto o edito un registro.
  */
 public function beforeSave()
 {
     if (parent::beforeSave()) {
         if (!empty($this->newPassword) && $this->newPassword == $this->rePassword) {
             $this->password = CPasswordHelper::hashPassword($this->newPassword);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 18
0
 public function authenticate()
 {
     $user = User::model()->findByAttributes(array('email' => $this->username, 'status' => array(User::STATUS_NORMAL, User::STATUS_BANNED)));
     if ($user === null || CPasswordHelper::verifyPassword($this->password, $user->password) === false) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     } else {
         $this->id = $user->id;
         $this->errorCode = self::ERROR_NONE;
     }
     return !$this->errorCode;
 }
Exemplo n.º 19
0
 /**
  * Password hashing
  * @return bool
  */
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         if ($this->isNewRecord) {
             $this->password = CPasswordHelper::hashPassword($this->password);
         }
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 20
0
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         $this->created = new CDbExpression('NOW()');
     }
     $this->updated = new CDbExpression('NOW()');
     if ($this->pass != '') {
         $this->password = CPasswordHelper::hashPassword($this->pass);
     }
     return parent::beforeSave();
 }
 /**
  * Updates the users password.
  * @param bool $runValidation
  */
 public function save($runValidation = true)
 {
     if ($runValidation && !$this->validate()) {
         return false;
     }
     /** @var AccountModule $account */
     $account = Yii::app()->getModule('account');
     //to avoid indirect modification error message
     $user = $this->user;
     $user->{$account->passwordField} = CPasswordHelper::hashPassword($this->new_password);
     return $user->save(false);
 }
Exemplo n.º 22
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionRegister()
 {
     $model = new User();
     $this->performAjaxValidation($model);
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->password = CPasswordHelper::hashPassword($model->password);
         if ($model->save()) {
             $this->redirect(array('site/login'));
         }
     }
     $this->render('register', array('model' => $model));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Usuarios'])) {
         $model->attributes = $_POST['Usuarios'];
         $model->Contrasena = CPasswordHelper::hashPassword($model->Contrasena);
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->idUsuario));
         }
     }
     $this->render('update', array('model' => $model));
 }
Exemplo n.º 24
0
 protected function beforeSave()
 {
     $this->username = trim(strtolower($this->username));
     if ($this->password === '') {
         $model2 = User::model()->findByPk($this->id);
         $this->password = $model2->password;
         $this->repeatPassword = $model2->password;
     } elseif ($this->repeatPassword !== null) {
         $this->unecryptedPassword = $this->password;
         $this->password = CPasswordHelper::hashPassword($this->password);
         $this->repeatPassword = CPasswordHelper::hashPassword($this->repeatPassword);
     }
     return true;
 }
Exemplo n.º 25
0
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     /** @var User $user */
     $user = User::model()->findByAttributes(array('username' => $this->username));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } elseif (!CPasswordHelper::verifyPassword($this->password, $user->password)) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     } else {
         $this->_id = $user->id;
         $this->errorCode = self::ERROR_NONE;
     }
     return !$this->errorCode;
 }
Exemplo n.º 26
0
 /**
  * Update password for the current user.
  */
 public function actionUpdatePassword()
 {
     $model = new UpdatePasswordForm();
     if (isset($_POST['UpdatePasswordForm'])) {
         $model->attributes = $_POST['UpdatePasswordForm'];
         if ($model->validate()) {
             Yii::app()->user->user->password = CPasswordHelper::hashPassword($model->new_password);
             Yii::app()->user->user->save();
             Yii::app()->user->setFlash('success', Yii::t("app", "Le mot de passe de votre compte a été modifié. Veuillez dès maintenant utiliser votre nouveau mot de passe pour vous identifier."));
             $this->redirect("index");
         }
     }
     $this->render('updatePassword', array('model' => $model));
 }
Exemplo n.º 27
0
 public function authenticate()
 {
     $record = User::model()->findByAttributes(['username' => $this->username]);
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!CPasswordHelper::verifyPassword($this->password, $record->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $record->id;
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
Exemplo n.º 28
0
 /**
  * Authenticates a user.
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $user = User::model()->find('LOWER(username)=?', array(strtolower($this->username)));
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!CPasswordHelper::verifyPassword($this->password, $user->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $user->id;
             $this->username = $user->username;
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return $this->errorCode == self::ERROR_NONE;
 }
Exemplo n.º 29
0
 public function authenticate()
 {
     $record = Usuario::model()->findByAttributes(array('user' => $this->username));
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!CPasswordHelper::verifyPassword($this->password, $record->clave)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $record->id;
             $this->setState('nombre', $record->nombre);
             $this->setState('rol', $record->rol);
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return !$this->errorCode;
 }
 /**
  * Updates the users password.
  * @param bool $runValidation
  */
 public function save($runValidation = true)
 {
     if ($runValidation && !$this->validate()) {
         return false;
     }
     /** @var AccountModule $account */
     $account = Yii::app()->getModule('account');
     $this->user->{$account->passwordField} = CPasswordHelper::hashPassword($this->new_password);
     if (!$this->user->save(false)) {
         return false;
     }
     if (!$this->userIdentity->authenticate() || !Yii::app()->user->login($this->userIdentity)) {
         return false;
     }
     Yii::app()->tokenManager->useToken('AccountLostPassword', $this->user_id, $this->token);
     return true;
 }