Пример #1
0
 /**
  * @param $string
  * @throws Exception
  * @return string
  */
 public function hashString($string)
 {
     $hasher = new \PasswordHash($this->_iterationCount, false);
     $hashAndType = $hasher->hashPassword($string);
     $check = $hasher->checkPassword($string, $hashAndType['hash']);
     if (!$check) {
         throw new Exception(Craft::t('Could not hash the given string.'));
     }
     return $hashAndType;
 }
Пример #2
0
 public function beforeSave()
 {
     $ph = new PasswordHash(Yii::app()->params['phpass']['iteration_count_log2'], Yii::app()->params['phpass']['portable_hashes']);
     //add the password hash if it's a new record
     if ($this->getIsNewRecord()) {
         $this->user_password = $ph->hashPassword($this->Password);
     } elseif (!empty($this->Password) && !empty($this->PasswordConfirm) && $this->Password === $this->PasswordConfirm) {
         $this->user_password = $ph->hashPassword($this->Password);
     } elseif (!empty($this->ResetPassword)) {
         $this->user_password = $ph->hashPassword($this->ResetPassword);
     }
     //$this->items = implode(', ', $this->items);
     return parent::beforeSave();
 }
Пример #3
0
 public function getUserData($password)
 {
     $password = PasswordHash::hashPassword($this->validateInput("guests", $password, "password"));
     return $this->loadUser($this->query(DBService::SELECT, "guests", array("COLUMNS" => array("`id`", "`Household name`", "`Has RSVPed`", "`Friend login` as `isFriend`", "(`Ceremony adults invited` + `Ceremony children invited`) as `ceremony invited`", "(`Reception adults invited` + `Reception children invited`) as `reception invited`", "(`Havdalah adults invited` + `Havdalah children invited`) as `havdalah invited`"), "WHERE" => "`password` = '" . $password . "'")));
 }
Пример #4
0
	/**
	 * Set the user's password using the necessary hashing
	 *
	 * @param $password
	 *
	 * @return bool|string True/False on success or failure, a string if on error.
	 */
	public function setPassword($password) {
		$isvalid = $this->validatePassword($password);

		if($isvalid !== true){
			// Core validation returned a string.... it's INVALID!
			return $isvalid;
		}

		// hash the password.
		$hasher = new \PasswordHash(datastore::HASH_ITERATIONS);
		$password = $hasher->hashPassword($password);

		// Still here?  Then try to set it.
		$this->_usermodel->set('password', $password);
		$this->_usermodel->set('last_password', DateTime::NowGMT());
		return true;
	}
Пример #5
0
 public function testGeneratedPasswordEncryption()
 {
     $sPassword = PasswordHash::generatePassword();
     $sHash = PasswordHash::hashPassword($sPassword);
     $this->assertSame(true, PasswordHash::comparePassword($sPassword, $sHash));
 }
Пример #6
0
 /**
  * Set a new password to an user account
  *
  * @param string $token Password token used to reset the account
  * @param string $password New password
  * @return bool
  */
 public function setNewPassword($token, $password)
 {
     $changed = false;
     $this->_db->beginTransaction();
     try {
         $tokenData = $this->_db->fetchFirstRequest('getPasswordResetByToken', array(':token' => $token));
         if (!empty($tokenData)) {
             $hasher = new PasswordHash(8, false);
             $hashedPassword = $hasher->hashPassword($password);
             if (!empty($hashedPassword)) {
                 $this->_db->executeRequest('changeUserPassword', array(':password' => $hashedPassword, ':id' => $tokenData['user_id']));
                 $this->_db->executeRequest('cleanTokens', array(':userId' => $tokenData['user_id']));
                 $changed = true;
             } else {
                 $this->_messenger->add('error', $this->_lang->get('passwordMiscError'));
             }
         }
     } catch (Exception $e) {
         $this->_db->rollBack();
         throw $e;
     }
     $this->_db->commit();
     return $changed;
 }