Get a description of the required password policy
Cyril Ogana <cogana@gmail.com>
2015-07-18

@return string

@access protected
@final
190883
final protected function _getPasswordPolicyDescription($policyType){
        $policyObj = $this->_getUdfPasswordPolicy();

        switch ($policyType) {
            case 'illegal_attempts_limit':
                if ($policyObj['illegal_attempts_limit'] > 0) {
                    return 'The illegal login attempts limit is '.$policyObj['illegal_attempts_limit'];
                }
            break;
            case 'password_reset_frequency':
                if ($policyObj['password_reset_frequency'] > 0) {
                    return 'The password reset frequency is '.$policyObj['password_reset_frequency'].' days';
                }
            break;
            case 'password_repeat_minimum':
                if ($policyObj['password_repeat_minimum'] > 0) {
                    return 'A user is not allowed to repeat any of their last '.$policyObj['password_repeat_minimum'].' passwords';
                }
            break;
            case 'illegal_attempts_penalty_seconds':
                if ($policyObj['illegal_attempts_penalty_seconds'] > 0) {
                    return 'A user account will be temporarily locked out after the illegal login attempts limit for '.$policyObj['illegal_attempts_penalty_seconds'].' seconds; and will require admin intervention if the offense is repeated';
                }
            break;
            default:
            
            break;
        }
    }
1169536
public function resetPassword() : string {
		$newPass = bin2hex(random_bytes(20));
		$newHash = password_hash($newPass, PASSWORD_BCRYPT);

		$stmt = $this->db->prepare(
			"UPDATE accounts SET pw_hash=? WHERE id=?;"
		);
		$stmt->bind_param("si", $newHash, $this->id);
		$stmt->execute();
		$this->db->commit();
		$this->pwHash = $newHash;

		$this->sessionManager->wipeLoginSession();
		return $newPass;
	}
1313943
private function getEmail(): ? string
    {
        $email = $this->ask("Enter email address");

        $validator = Validator::make(['email' => $email], [
            'email' => 'required|min:3|email',
        ]);

        if ($validator->fails()) {
            $this->error('Email is required, minimum 3 symbols length and must be email format');

            return $this->getEmail();
        }

        $this->email = $email;

        return null;
    }
721354
public static function getPublicInfo()
    {
        if (empty(session('user'))) {
            throw new UnauthorizedException('There is no valid session for the current request.');
        }

        $sessionData = [
            'session_token'   => session('session_token'),
            'session_id'      => session('session_token'), // temp for compatibility with 1.x
            'id'              => session('user.id'),
            'name'            => session('user.display_name'),
            'first_name'      => session('user.first_name'),
            'last_name'       => session('user.last_name'),
            'email'           => session('user.email'),
            'is_sys_admin'    => session('user.is_sys_admin'),
            'last_login_date' => session('user.last_login_date'),
            'host'            => gethostname()
        ];

        $role = static::get('role');
        if (!session('user.is_sys_admin') && !empty($role)) {
            $sessionData['role'] = array_get($role, 'name');
            $sessionData['role_id'] = array_get($role, 'id');
        }

        return $sessionData;
    }
1360186
public function getPrivateKeyPassphrase()
    {
        if (isset($this->raw->{'key-pass'})
            && is_string($this->raw->{'key-pass'})) {
            return $this->raw->{'key-pass'};
        }

        return null;
    }
295467
public function credential()
    {
        if (!$username = $this->username()) {
            return '';
        }
        $credentials = $username;
        if ($password = $this->password()) {
            $credentials .= ':' . $password;
        }
        return $credentials;
    }
1082323
public function getPassword()
    {
        if (!array_key_exists(self::PASSWORD, $this->passwd)) {
            throw new \Exception('Could not get user password from passwd.');
        }
        return $this->passwd[self::PASSWORD];
    }
652285
public function toString()
    {
        $authorizations = array();

        $authorizations['Date'] = $this->date;
        $authorizations['CurrentPage'] = $this->currentPage;
        $authorizations['TotalPages'] = $this->totalPages;
        $authorizations['Transactions in this page'] = $this->resultsInThisPage;

        return "PagSeguroAuthorizationsSearchResult: " . implode(' - ', $authorizations);

    }
1205853
public function getAuthPasswordParamName() : ?string
   {

      foreach ( $this->_attributes as $attribute )
      {
         if ( Type::PASSWORD_PARAM === $attribute->getType() )
         {
            return $attribute->getName();
         }
      }

      return null;

   }
404013
public function generatePassword()
    {
        $choice = null;

        while(! in_array($choice, [1, 2])) {
            $this->info('What type of generated password would you like?');
            $this->info('[1] WordBased');
            $this->info('[2] Random');
            $choice = $this->ask('Please make a selection');

            if ($choice == 1) {
                return $this->makeGenerated('wordbased');
            }
            if ($choice == 2) {
                return $this->makeGenerated('random');
            }
        }
    }
462576
public function getKey(): string
    {
        $argKeys = $this->argKeys();

        return $this->implode([
            $this->privateCache
                ? 'auth'
                : null,
            $this->privateCache
                ? app('auth')->user()->getKey()
                : null,
            strtolower($this->resolveInfo->parentType->name),
            $this->fieldKey,
            strtolower($this->resolveInfo->fieldName),
            $argKeys->isNotEmpty()
                ? $argKeys->implode(':')
                : null,
        ]);
    }
663667
public function actionInscription()
    {
        $form = $this->getInscriptionForm();
        if ($form->isValid()) {
            $user = $this->getUserModel()
                ->set('login', $form->login)
                ->set('password', $form->password);
            try {
                $saved = FALSE;
                $saved = $user->save();
            } catch (\PDOException $e) {
            }
            if ($saved) {
                $this->login($user);
                Notif::success(sprintf(static::MSG_INSCRIPTION_VALID, $form->login));
                \Staq\Util::httpRedirectUri($this->getRedirectUri());
            } else {
                Notif::error(static::MSG_INSCRIPTION_KO);
            }
        }
        $view = $this->createView('inscription');
        $view['form'] = $form;
        $view['redirect'] = $this->getRedirectUri();
        return $view;
    }
388495
public function getDescription(): string
    {
        if (!$this->minValue) {
            return __('must have a length lower than "%d"', $this->maxValue);
        }
        if (!$this->maxValue) {
            return __('must have a length greater than "%d"', $this->minValue);
        }
        if ($this->minValue === $this->maxValue) {
            return __('must have a length "%d"', $this->minValue);
        }
        return __('must have a length between "%d" and "%d"', $this->minValue, $this->maxValue);
    }
1175596
public function getRoleAsString()
  {
  	$options = self::getRoleOptions();
  	return isset($options[$this->role]) ? $options[$this->role] : '';
  }
1309353
public function generatePassword()
    {
        $salts = Site::salts(12);
        $special_char1 = '~<>?|:.(),';
        $special_char2 = '!@#$%^&*_+-*+';
        $pass = $special_char2.$salts.$special_char1;

        return str_shuffle($pass);
    }
893355
public function getPasswordElement()
    {
        $element = $this->getElement($this->passwordFieldName);

        if (! $element) {
            // Veld password
            $element = $this->createElement('password', $this->passwordFieldName);
            $element->setLabel($this->translate->_('Password'));
            $element->setAttrib('size', 40);
            $element->setRequired(true);

            if ($this->getOrganizationElement() instanceof \Zend_Form_Element_Hidden) {
                $explain = $this->translate->_('Combination of user and password not found.');
            } else {
                $explain = $this->translate->_('Combination of user and password not found for this organization.');
            }
            $element->addValidator(new \Gems_User_Validate_GetUserPasswordValidator($this, $explain));

            $this->addElement($element);
        }

        return $element;
    }
959359
protected function getConfigFormat()
    {
        $conf = $this->username;
        if (!empty($this->server)) {
            $conf .= ';'.$this->server;
        }

        $conf .= ' '.$this->password;

        if (!empty($this->alias)) {
            $conf .= ' '.$this->alias;
        }

        return $conf;
    }