13 private static function getAlgorithm(
string $algorithmName): string
15 if (!$algorithmName) {
33 if (array_key_exists($algorithmName, $mapping)) {
34 return $mapping[$algorithmName];
37 throw new Exception(
'Unsupported password algorithm: ' . $algorithmName);
55 $chars = preg_split(
'//', $pPassword, -1, PREG_SPLIT_NO_EMPTY);
56 foreach ($chars as $char) {
57 $value = ord($char) << $charPos++;
58 $rotated_bits = $value >> 15;
83 public static function hashPassword(
string $password,
string $algorithm =
'',
string $salt =
'',
int $spinCount = 10000): string
85 $phpAlgorithm = self::getAlgorithm($algorithm);
87 return self::defaultHashPassword($password);
90 $saltValue = base64_decode($salt);
91 $encodedPassword = mb_convert_encoding($password,
'UCS-2LE',
'UTF-8');
93 $hashValue =
hash($phpAlgorithm, $saltValue . $encodedPassword,
true);
94 for (
$i = 0;
$i < $spinCount; ++
$i) {
95 $hashValue =
hash($phpAlgorithm, $hashValue . pack(
'L',
$i),
true);
98 return base64_encode($hashValue);
const ALGORITHM_WHIRLPOOL
static defaultHashPassword(string $pPassword)
Create a password hash from a given string.
static hashPassword(string $password, string $algorithm='', string $salt='', int $spinCount=10000)
Create a password hash from a given string by a specific algorithm.
const ALGORITHM_RIPEMD_128
const ALGORITHM_RIPEMD_160
static getAlgorithm(string $algorithmName)
Get algorithm name for PHP.
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.