Source of file PBKDF2.php
Size: 1,429 Bytes - Last Modified: 2021-12-24T06:43:15+00:00
/var/www/docs.ssmods.com/process/src/src/PasswordEncryptor/PBKDF2.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 | <?php declare(strict_types=1); namespace CWP\Core\PasswordEncryptor; use Exception; use SilverStripe\Security\PasswordEncryptor_PHPHash; /** * Provides Password-Based Key Derivation Function hashing for passwords, using the provided algorithm (default * is SHA512), which is NZISM compliant under version 3.2 section 17.2. */ class PBKDF2 extends PasswordEncryptor_PHPHash { /** * The number of internal iterations for hash_pbkdf2() to perform for the derivation. Please note that if you * change this from the default value you will break existing hashes stored in the database, so these would * need to be regenerated. * * @var int */ protected $iterations = 30000; /** * @param string $algorithm * @param int|null $iterations * @throws Exception If the provided algorithm is not available in the current environment */ public function __construct(string $algorithm, int $iterations = null) { parent::__construct($algorithm); if ($iterations !== null) { $this->iterations = $iterations; } } /** * @return int */ public function getIterations(): int { return $this->iterations; } public function encrypt($password, $salt = null, $member = null) { return hash_pbkdf2($this->getAlgorithm(), (string) $password, (string) $salt, $this->getIterations()); } } |