silverstripe-framework/Security/PasswordEncryptor_PHPHash.php
Damian Mooyman 8dd644d25d
API Namespace all classes
Namespace all templates
Move difflib and BBCodeParser2 to thirdparty
Remove deprecated API marked for removal in 4.0
2016-09-08 10:23:17 +12:00

45 lines
882 B
PHP

<?php
namespace SilverStripe\Security;
use Exception;
/**
* Encryption using built-in hash types in PHP.
* Please note that the implemented algorithms depend on the PHP
* distribution and architecture.
*/
class PasswordEncryptor_PHPHash extends PasswordEncryptor
{
protected $algorithm = 'sha1';
/**
* @param string $algorithm A PHP built-in hashing algorithm as defined by hash_algos()
* @throws Exception
*/
public function __construct($algorithm)
{
if (!in_array($algorithm, hash_algos())) {
throw new Exception(
sprintf('Hash algorithm "%s" not found in hash_algos()', $algorithm)
);
}
$this->algorithm = $algorithm;
}
/**
* @return string
*/
public function getAlgorithm()
{
return $this->algorithm;
}
public function encrypt($password, $salt = null, $member = null)
{
return hash($this->algorithm, $password . $salt);
}
}