3 declare(strict_types=1);
    26     public static function isPassword(
string $a_passwd, ?
string &$customError = null): bool
    30         $lng = $DIC->language();
    35         if (empty($a_passwd)) {
    36             $customError = 
$lng->txt(
'password_empty');
    44         if ($security->getPasswordMinLength() > 0 && strlen($a_passwd) < $security->getPasswordMinLength()) {
    45             $errors[] = sprintf(
$lng->txt(
'password_to_short'), $security->getPasswordMinLength());
    51         if ($security->getPasswordMaxLength() > 0 && strlen($a_passwd) > $security->getPasswordMaxLength()) {
    52             $errors[] = sprintf(
$lng->txt(
'password_to_long'), $security->getPasswordMaxLength());
    57         if ($security->isPasswordCharsAndNumbersEnabled()) {
    58             $hasCharsAndNumbers = 
true;
    61             if (!preg_match(
'/[A-Za-z]+/', $a_passwd)) {
    62                 $hasCharsAndNumbers = 
false;
    66             if (!preg_match(
'/[0-9]+/', $a_passwd)) {
    67                 $hasCharsAndNumbers = 
false;
    70             if (!$hasCharsAndNumbers) {
    71                 $errors[] = 
$lng->txt(
'password_must_chars_and_numbers');
    76         if ($security->getPasswordNumberOfUppercaseChars() > 0) {
    78                 preg_replace(
'/[A-Z]/', 
'', $a_passwd)
    79             ) < $security->getPasswordNumberOfUppercaseChars()) {
    81                     $lng->txt(
'password_must_contain_ucase_chars'),
    82                     $security->getPasswordNumberOfUppercaseChars()
    88         if ($security->getPasswordNumberOfLowercaseChars() > 0) {
    90                 preg_replace(
'/[a-z]/', 
'', $a_passwd)
    91             ) < $security->getPasswordNumberOfLowercaseChars()) {
    93                     $lng->txt(
'password_must_contain_lcase_chars'),
    94                     $security->getPasswordNumberOfLowercaseChars()
   101         if ($security->isPasswordSpecialCharsEnabled()) {
   103             if (!preg_match(self::getPasswordValidChars(
true, 
true), $a_passwd)) {
   104                 $errors[] = 
$lng->txt(
'password_must_special_chars');
   110         if (!preg_match(self::getPasswordValidChars(), $a_passwd)) {
   111             $errors[] = 
$lng->txt(
'password_contains_invalid_chars');
   116         if (count($errors) == 1) {
   117             $customError = $errors[0];
   118         } elseif (count($errors) > 1) {
   119             $customError = 
$lng->txt(
'password_multiple_errors');
   120             $customError .= 
'<br />' . implode(
'<br />', $errors);
   136             if ($a_only_special_chars) {
   137                 return '/[_\.\+\?\#\-\*\@!\$\%\~\/\:\;]+/';
   139                 return '/^[A-Za-z0-9_\.\+\?\#\-\*\@!\$\%\~\/\:\;]+$/';
   142             return 'A-Z a-z 0-9 _.+?#-*@!$%~/:;';
   153         string $clear_text_password,
   155         ?
string &$error_language_variable = null
   161         if (is_string($user)) {
   163         } elseif (is_array($user)) {
   165             $login = $user[
'login'];
   166             $userId = $user[
'id'];
   168             $login = $user->getLogin();
   169             $userId = $user->getId();
   174         if ($login && (
int) $security->getPasswordMustNotContainLoginnameStatus() &&
   175             strpos(strtolower($clear_text_password), strtolower($login)) !== false
   177             $error_language_variable = 
'password_contains_parts_of_login_err';
   194         $lng = $DIC->language();
   198         $infos = [sprintf(
$lng->txt(
'password_allow_chars'), self::getPasswordValidChars(
false))];
   201         if ($security->getPasswordMinLength() > 0) {
   202             $infos[] = sprintf(
$lng->txt(
'password_to_short'), $security->getPasswordMinLength());
   206         if ($security->getPasswordMaxLength() > 0) {
   207             $infos[] = sprintf(
$lng->txt(
'password_to_long'), $security->getPasswordMaxLength());
   211         if ($security->isPasswordCharsAndNumbersEnabled()) {
   212             $infos[] = 
$lng->txt(
'password_must_chars_and_numbers');
   216         if ($security->isPasswordSpecialCharsEnabled()) {
   217             $infos[] = 
$lng->txt(
'password_must_special_chars');
   220         if ($security->getPasswordNumberOfUppercaseChars() > 0) {
   222                 $lng->txt(
'password_must_contain_ucase_chars'),
   223                 $security->getPasswordNumberOfUppercaseChars()
   227         if ($security->getPasswordNumberOfLowercaseChars() > 0) {
   229                 $lng->txt(
'password_must_contain_lcase_chars'),
   230                 $security->getPasswordNumberOfLowercaseChars()
   234         return implode(
'<br />', $infos);
   246         srand((
int) microtime() * 1000000);
   250         for ($i = 1; $i <= $a_number; $i++) {
   251             $min = ($security->getPasswordMinLength() > 0)
   252                 ? $security->getPasswordMinLength()
   254             $max = ($security->getPasswordMaxLength() > 0)
   255                 ? max($security->getPasswordMaxLength(), $min)
   259             $length = $random->int($min, $max);
   260             $next = $random->int(1, 2);
   262             $vowels_uc = strtoupper($vowels);
   263             $consonants = 
"bcdfghjklmnpqrstvwxyz";
   264             $consonants_uc = strtoupper($consonants);
   265             $numbers = 
"1234567890";
   266             $special = 
"_.+?#-*@!$%~";
   269             if ($security->getPasswordNumberOfUppercaseChars() > 0) {
   270                 for ($j = 0; $j < $security->getPasswordNumberOfUppercaseChars(); $j++) {
   273                             $pw .= $consonants_uc[$random->int(0, strlen($consonants_uc) - 1)];
   278                             $pw .= $vowels_uc[$random->int(0, strlen($vowels_uc) - 1)];
   285             if ($security->isPasswordCharsAndNumbersEnabled()) {
   286                 $pw .= $numbers[$random->int(0, strlen($numbers) - 1)];
   289             if ($security->isPasswordSpecialCharsEnabled()) {
   290                 $pw .= $special[$random->int(0, strlen($special) - 1)];
   293             $num_lcase_chars = max($security->getPasswordNumberOfLowercaseChars(), $length - strlen($pw));
   294             for ($j = 0; $j < $num_lcase_chars; $j++) {
   297                         $pw .= $consonants[$random->int(0, strlen($consonants) - 1)];
   302                         $pw .= $vowels[$random->int(0, strlen($vowels) - 1)];
   308             $pw = str_shuffle($pw);
 static isPassword(string $a_passwd, ?string &$customError=null)
 
static getPasswordValidChars(bool $a_as_regex=true, bool $a_only_special_chars=false)
All valid chars for password. 
 
static strLen(string $a_string)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
static isPasswordValidForUserContext(string $clear_text_password, $user, ?string &$error_language_variable=null)
 
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo() 
 
static generatePasswords(int $a_number)
Generate a number of passwords. 
 
Wrapper for generation of random numbers, strings, bytes. 
 
static _getInstance()
Get instance of ilSecuritySettings.