/*!
\static
\return an array with characters which are allowed in password.
519645
static function passwordCharacterTable()
    {
        if ( !empty( $GLOBALS['eZUserPasswordCharacterTable'] ) )
        {
            return $GLOBALS['eZUserPasswordCharacterTable'];
        }
        $table = array_merge( range( 'a', 'z' ), range( 'A', 'Z' ), range( 0, 9 ) );

        $ini = eZINI::instance();
        if ( $ini->variable( 'UserSettings', 'UseSpecialCharacters' ) == 'true' )
        {
            $specialCharacters = '!#%&{[]}+?;:*';
            $table = array_merge( $table, preg_split( '//', $specialCharacters, -1, PREG_SPLIT_NO_EMPTY ) );
        }
        // Remove some characters that are too similar visually
        $table = array_diff( $table, array( 'I', 'l', 'o', 'O', '0' ) );
        $tableTmp = $table;
        $table = array();
        foreach ( $tableTmp as $item )
        {
            $table[] = $item;
        }

        return $GLOBALS['eZUserPasswordCharacterTable'] = $table;
    }
1367393
protected function allowedTypes()
    {
        return [
            self::TYPE_DEFAULT_MESSAGE,
            self::TYPE_REGISTRATION_MESSAGE,
            self::TYPE_RESET_PASSWORD_MESSAGE,
            self::TYPE_LOGIN_MESSAGE,
            self::TYPE_NOTIFICATION_MESSAGE,
        ];
    }
891907
public function allowedHttpVerbs() : array
    {
        return [
            HttpRequest::METHOD_GET,
            HttpRequest::METHOD_POST,
            HttpRequest::METHOD_PATCH,
            HttpRequest::METHOD_DELETE,
            HttpRequest::METHOD_HEAD,
            HttpRequest::METHOD_OPTIONS,
        ];
    }
298992
public static function getAllowedExtensions()
    {
        $config = static::config()->get('allowed_extensions');

        $allowedExtensions = [];
        foreach ($config as $key => $value) {
            if (is_int($key)) {
                // Numeric indexes, example: [jpg, png, gif]
                $key = $value;
                $value = true;
            }

            // Skip disabled extensions
            if (in_array($value, [null, false], true)) {
                continue;
            }

            $allowedExtensions[] = strtolower($key);
        }
        return $allowedExtensions;
    }
540153
public function checkUsername() {
    if (!Tilmeld::$config['email_usernames']) {
      if (empty($this->username)) {
        return ['result' => false, 'message' => 'Please specify a username.'];
      }
      if (Tilmeld::$config['max_username_length'] > 0
          && strlen($this->username) > Tilmeld::$config['max_username_length']
        ) {
        return [
          'result' => false,
          'message' => 'Usernames must not exceed '.
            Tilmeld::$config['max_username_length'].' characters.'
        ];
      }
      if (array_diff(
          str_split($this->username),
          str_split(Tilmeld::$config['valid_chars'])
      )) {
        return [
          'result' => false,
          'message' => Tilmeld::$config['valid_chars_notice']
        ];
      }
      if (!preg_match(Tilmeld::$config['valid_regex'], $this->username)) {
        return [
          'result' => false,
          'message' => Tilmeld::$config['valid_regex_notice']
        ];
      }
      $selector = ['&',
        'ilike' => [
          'username',
          str_replace(
              ['\\', '%', '_'],
              ['\\\\\\\\', '\%', '\_'],
              $this->username
          )
        ]
      ];
      if (isset($this->guid)) {
        $selector['!guid'] = $this->guid;
      }
      $test = Nymph::getEntity(
          ['class' => '\Tilmeld\Entities\User', 'skip_ac' => true],
          $selector
      );
      if (isset($test->guid)) {
        return ['result' => false, 'message' => 'That username is taken.'];
      }

      return [
        'result' => true,
        'message' => (
          isset($this->guid) ? 'Username is valid.' : 'Username is available!'
        )
      ];
    } else {
      if (empty($this->username)) {
        return ['result' => false, 'message' => 'Please specify an email.'];
      }
      if (Tilmeld::$config['max_username_length'] > 0
          && strlen($this->username) > Tilmeld::$config['max_username_length']
        ) {
        return [
          'result' => false,
          'message' => 'Emails must not exceed '.
            Tilmeld::$config['max_username_length'].' characters.'
        ];
      }

      return $this->checkEmail();
    }
  }
1162429
public function generateForgotPasswordResetToken()
    {
        $username = $this->httpRequest()->post('username');

        $token = $this->getLoginInstance()->generateDeviceValidationToken($username);
        return ['passwordResetToken' => $token];
    }
619315
public static function match($password, array $userInputs = [])
    {
        $groups = static::group($password);
        $matches = [];

        $k = 0;
        foreach ($groups as $group) {
            $char = $group[0];
            $length = strlen($group);

            if ($length > 2) {
                $end = $k + $length - 1;
                $token = substr($password, $k, $end + 1);
                $matches[] = new static($password, $k, $end, $token, $char);
            }
            $k += $length;
        }

        return $matches;
    }
1332572
private function getBlacklistPasswords(): Generator
    {
        $fh = fopen($this->file, 'rb');

        while (($password = fgets($fh)) !== false) {
            yield trim($password);
        }

        fclose($fh);
    }
158103
public function encode()
    {
        $reserved = [
            '!%21!ui' => "!",
            '!%23!ui' => "#",
            '!%24!ui' => "$",
            '!%26!ui' => "&",
            '!%27!ui' => "'",
            '!%28!ui' => "(",
            '!%29!ui' => ")",
            '!%2A!ui' => "*",
            '!%2B!ui' => "+",
            '!%2C!ui' => ",",
            '!%2F!ui' => "/",
            '!%3A!ui' => ":",
            '!%3B!ui' => ";",
            '!%3D!ui' => "=",
            '!%3F!ui' => "?",
            '!%40!ui' => "@",
            '!%5B!ui' => "[",
            '!%5D!ui' => "]",
            '!%25!ui' => "%",
        ];
        // The % character must be the last in the $reserved array.
        // This makes sure that the already encoded values are not lost or encoded again.
        $this->uri = preg_replace(array_keys($reserved), array_values($reserved), rawurlencode($this->uri));
        return $this->baseToLowercase();
    }
168053
protected static function getSubstitutions($password)
    {
        $map = [];

        $l33t = [
            'a' => ['4', '@'],
            'b' => ['8'],
            'c' => ['(', '{', '[', '<'],
            'e' => ['3'],
            'g' => ['6', '9'],
            'i' => ['1', '!', '|'],
            'l' => ['1', '|', '7'],
            'o' => ['0'],
            's' => ['$', '5'],
            't' => ['+', '7'],
            'x' => ['%'],
            'z' => ['2'],
        ];
        // Simplified l33t table to reduce duplicates.
        $l33t = [
            'a' => ['4', '@'],
            'b' => ['8'],
            'c' => ['(', '{', '[', '<'],
            'e' => ['3'],
            'g' => ['6', '9'],
            'i' => ['1', '!'],
            'l' => ['|', '7'],
            'o' => ['0'],
            's' => ['$', '5'],
            't' => ['+', '7'],
            'x' => ['%'],
            'z' => ['2'],
        ];

        /*$chars = array_unique(str_split($password));
        foreach ($l33t as $letter => $subs) {
            $relevent_subs = array_intersect($subs, $chars);
            if (!empty($relevent_subs)) {
                $map[] = $relevent_subs;
            }
        }*/

        foreach (range(0, strlen($password) - 1) as $i) {
            $map[$i] = null;
            foreach ($l33t as $char => $subs) {
                if (in_array($password[$i], $subs, true)) {
                    $map[$i] = $char;
                }
            }
        }

        return $map;
    }
806391
public function getPasswordStrengthRules()
    {
        if ($this->_passwordStrengthRules === null) {
            $this->_passwordStrengthRules = [
                ['newPassword', 'string', 'min' => 8, 'message' => Yii::t('usr', 'New password must contain at least 8 characters.')],
                ['newPassword', 'match', 'pattern' => '/^.*(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/', 'message'    => Yii::t('usr', 'New password must contain at least one lower and upper case character and a digit.')],
            ];
        }

        return $this->_passwordStrengthRules;
    }
27656
public function getAnonymizeed()
	{
		$userinfo = $this->toObject();
		$userinfo->password_clear = '******';
		if (isset($userinfo->password)) {
			$userinfo->password = substr($userinfo->password, 0, 6) . '********';
		}
		if (isset($userinfo->password_salt)) {
			$userinfo->password_salt = substr($userinfo->password_salt, 0, 4) . '*****';
		}
		return $userinfo;
	}
1361807
public static function _randomPassword ($length = self::DEFAULT_PASSWORD_LENGTH, $charset = self::DEFAULT_PASSWORD_CHARACTERS)
	{
		
		// Set password variable
		
		$password	= '';

		// Set i to the password length
		
		$i = $length;

		// Loop until the password is the desired length
		
		while ($i > 0)
		{
			
			// Choose a random character from the charset
			
			$char = $charset[mt_rand (0, strlen ($charset) -1)];

			// Make sure that the first character of the password is a number or letter
			
			if ($password == '' && !preg_match('/[0-9A-Za-z]/', $char))
			{
				continue;
			}
			
			// Add the character to the password
			
			$password .= $char;

			// Decrement rounds
			
			$i--;

		}

		// Return the password
		
		return $password;

	}
1269199
@Sensitive
    public char[] getChars() {
        if (_password != null) {
            if (_password.length != 0) {
                char[] result = new char[_password.length];
                System.arraycopy(_password, 0, result, 0, _password.length);
                return result;
            } else {
                return _password; // Can safely return the empty array - caller
                // can't change it!
            }
        } else {
            return null;
        }
    }
912379
protected function Wordings()
    {
        $result = array();
        $result[] = 'Success';
        $result[] = 'Error';
        $result[] = 'Password';
        $result[] = 'Password.Validation.Required.Missing';
        $result[] = 'PasswordRepeat';
        $result[] = 'PasswordRepeat.Validation.Required.Missing';
        $result[] = 'PasswordRepeat.Validation.CompareCheck.EqualsNot_{0}';
        $result[] = 'PasswordChangeSubmit';
        return $result;
    }
1142474
function password_hash($password)
	{
		$result = md5($password);
		if (!$this->conf['backward']['weak_password'])
		{
			$result = md5($result);
		}
		return $result;
	}
482661
protected static function datesWithoutSeparators($password)
    {
        $dateMatches = [];

        // 1197 is length-4, 01011997 is length 8
        foreach (static::findAll($password, '/(\d{4,8})/') as $captures) {
            $capture = $captures[1];
            $begin = $capture['begin'];
            $end = $capture['end'];

            $token = $capture['token'];
            $tokenLen = strlen($token);

            // Create year candidates.
            $candidates1 = [];
            if ($tokenLen <= 6) {
                // 2 digit year prefix (990112)
                $candidates1[] = [
                    'daymonth' => substr($token, 2),
                    'year' => substr($token, 0, 2),
                    'begin' => $begin,
                    'end' => $end,
                ];
                // 2 digit year suffix (011299)
                $candidates1[] = [
                    'daymonth' => substr($token, 0, $tokenLen - 2),
                    'year' => substr($token, -2),
                    'begin' => $begin,
                    'end' => $end,
                ];
            }
            if ($tokenLen >= 6) {
                // 4 digit year prefix (199912)
                $candidates1[] = [
                    'daymonth' => substr($token, 4),
                    'year' => substr($token, 0, 4),
                    'begin' => $begin,
                    'end' => $end,
                ];
                // 4 digit year suffix (121999)
                $candidates1[] = [
                    'daymonth' => substr($token, 0, $tokenLen - 4),
                    'year' => substr($token, -4),
                    'begin' => $begin,
                    'end' => $end,
                ];
            }
            // Create day/month candidates from years.
            $candidates2 = [];
            foreach ($candidates1 as $candidate) {
                switch (strlen($candidate['daymonth'])) {
                    case 2: // ex. 1 1 97
                        $candidates2[] = [
                            'day' => $candidate['daymonth'][0],
                            'month' => $candidate['daymonth'][1],
                            'year' => $candidate['year'],
                            'begin' => $candidate['begin'],
                            'end' => $candidate['end'],
                        ];

                        break;
                    case 3: // ex. 11 1 97 or 1 11 97
                        $candidates2[] = [
                            'day' => substr($candidate['daymonth'], 0, 2),
                            'month' => substr($candidate['daymonth'], 2),
                            'year' => $candidate['year'],
                            'begin' => $candidate['begin'],
                            'end' => $candidate['end'],
                        ];
                        $candidates2[] = [
                            'day' => substr($candidate['daymonth'], 0, 1),
                            'month' => substr($candidate['daymonth'], 1, 3),
                            'year' => $candidate['year'],
                            'begin' => $candidate['begin'],
                            'end' => $candidate['end'],
                        ];

                        break;
                    case 4: // ex. 11 11 97
                        $candidates2[] = [
                            'day' => substr($candidate['daymonth'], 0, 2),
                            'month' => substr($candidate['daymonth'], 2, 4),
                            'year' => $candidate['year'],
                            'begin' => $candidate['begin'],
                            'end' => $candidate['end'],
                        ];

                        break;
                }
            }
            // Reject invalid candidates
            foreach ($candidates2 as $candidate) {
                $day = (int) $candidate['day'];
                $month = (int) $candidate['month'];
                $year = (int) $candidate['year'];

                $date = static::checkDate($day, $month, $year);
                if (false === $date) {
                    continue;
                }
                list($day, $month, $year) = $date;

                $dateMatches[] = [
                    'begin' => $candidate['begin'],
                    'end' => $candidate['end'],
                    'token' => substr($password, $begin, $begin + $end - 1),
                    'separator' => '',
                    'day' => $day,
                    'month' => $month,
                    'year' => $year,
                ];
            }
        }

        return $dateMatches;
    }