@param $password

@return string
@throws PasswordConstraintsException
979194
public function encrypt($password)
    {

        if (PasswordConstraintsService::singleton()->validate($password)) {
            $salt = helpers_Random::generateString($this->getSaltLength());
            return $salt.hash($this->getAlgorithm(), $salt.$password);
        }

        throw new PasswordConstraintsException(
            __( 'Password must be: %s' ,
            implode( ',', PasswordConstraintsService::singleton()->getErrors() )
        ));
    }
309172
public function setPassword($password)
    {
        $this->password    = $password;
        $encryptedPassword = $this->getEncryptedPassword($password, $this->getSecret(), $this->getRequestAuthenticator());

        $this->setAttribute(2, $encryptedPassword);

        return $this;
    }
1056295
public static function getHashedPasswordWithSalt($password) {
		
		// salt for bcrypt needs to be 22 base64 characters (only [./0-9A-Za-z])
		$salt = substr(str_replace('+', '.', base64_encode(sha1(microtime(true), true))), 0, 22);
		
		// 2a = bcrypt algorithm selector, 12 = the workload factor
		$hash = crypt($password, '$2a$12$' . $salt);
		
		return $hash;

	}
423127
public function checkPassword($password) {
    switch (Tilmeld::$config['pw_method']) {
      case 'plain':
        return ($this->password == $password);
      case 'digest':
        return ($this->password == hash('sha256', $password));
      case 'salt':
      default:
        return ($this->password == hash('sha256', $password.$this->salt));
    }
  }
684624
private function enforcePasswordStrength(string $password)
    {
        if ($this->passwordChecker && !$this->passwordChecker->isStrongPassword($password)) {
            throw new WeakPasswordException();
        }
    }
923283
public function encryptPassword($password, $salt = null)
    {
        if (!is_string($this->password_encryption) && is_callable($this->password_encryption)) {
            $e = $this->password_encryption;

            return $e($password, $salt);
        }
        if ($this->password_encryption) {
            $this->debug("Encrypting password: '$password' with ".$this->password_encryption.' salt='.$salt);
        }
        switch ($this->password_encryption) {
            case null:
                return $password;
            case 'php':
                // returns false on failure
                return password_hash($password, $this->hash_algo, $this->hash_options);
            case 'sha256/salt':
                if ($salt === null) {
                    throw $this->exception(
                        'sha256 requires salt (2nd argument to encryptPassword and is normaly an email)'
                    );
                }
                $key = $this->app->getConfig('auth/key', $this->app->name);
                if ($this->password_encryption) {
                    $this->debug('Using key '.$key);
                }

                return hash_hmac('sha256', $password.$salt, $key);
            case 'sha1':
                return sha1($password);
            case 'md5':
                return md5($password);
            case 'rot13':
                return str_rot13($password);
            default:
                throw $this->exception('No such encryption method')
                    ->addMoreInfo('encryption', $this->password_encryption);
        }
    }
278505
public function setPassword($password)
    {
        $this->definition->setPassword($this, $password);
        $this->setPasswordResetRequired(false);
        $this->refresh();   // force refresh
        return $this;
    }
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;
    }
793837
public function convertPassword($password)
    {
        if (self::TYPE_PASSWORD_DIGEST === $this->getTypeValue()) {
            $password = $this->digestPassword($password);
        }

        return $password;
    }
161110
public static function cryptHash($password)
    {
        $salt = substr(base64_encode(chr(mt_rand(0, 255))), 0, 2);
        $salt = str_replace('+', '.', $salt);
        return crypt($password, $salt);
    }
973709
protected function createNTLMPassword($password, $challenge)
    {
        // FIRST PART
        $ntlmHash = $this->createByte($this->md4Encrypt($password), 21, false);
        list($key1, $key2, $key3) = str_split($ntlmHash, 7);

        $desKey1 = $this->createDesKey($key1);
        $desKey2 = $this->createDesKey($key2);
        $desKey3 = $this->createDesKey($key3);

        return $this->desEncrypt($challenge, $desKey1).$this->desEncrypt($challenge, $desKey2).$this->desEncrypt($challenge, $desKey3);
    }
301969
protected function setPassword($password) {
        if (!isset($password)) $password = '';
        else if (!is_string($password)) throw new IllegalTypeException('Illegal type of parameter $password: '.gettype($password));

        $this->password = $password;
        return $this;
    }
221226
public function encode( $password, $salt = null )
	{
		return ( isset( $this->hasher ) ? $this->hasher->getHashedPassword( $password, $salt ) : $password );
	}
825131
private function isLongEnough(string $password): bool
    {
        if ((int) $this->constraints['minLength'] > 0) {
            return mb_strlen($password) >= (int) $this->constraints['minLength'];
        }

        return true;
    }
501157
protected function bCrypt($password)
    {
        if ($this->isSamePasswordOption()) {
            $result = $this->gameDataService->hashPassword($password);
        } else {
            $bCrypt = new Bcrypt();
            $result = $bCrypt->create($password);
        }

        return $result;
    }
309725
public function setPlainPassword($password)
    {
        $this['salt'] || $this['salt'] = $this->password->generateSalt();
        $this['password'] = $this->password->hash($password, $this['salt']);

        return $this;
    }
626914
protected function protect($password, $salt = null)
    {
        $salt = isset($salt)
            ? $salt
            : $this->salt;

        return $password . $salt;
    }