summaryrefslogtreecommitdiffstats
path: root/Encoder
diff options
context:
space:
mode:
authorJohannes Schmitt <schmittjoh@gmail.com>2010-10-21 23:58:31 +0200
committerFabien Potencier <fabien.potencier@gmail.com>2010-10-22 13:24:29 +0200
commit89174563c47a0ec86ac39aaa480df6ab404288f1 (patch)
treef832f862f006417b7d0f095355d6bde6e136cd7c /Encoder
parent7670a7c784b4ad1723f38fc576145f23dcc0e80d (diff)
downloadsymfony-security-89174563c47a0ec86ac39aaa480df6ab404288f1.zip
symfony-security-89174563c47a0ec86ac39aaa480df6ab404288f1.tar.gz
symfony-security-89174563c47a0ec86ac39aaa480df6ab404288f1.tar.bz2
[Security] changed encoders to use hash() function whenver possible and replaced sha1 with sha256 as default algorithm
Diffstat (limited to 'Encoder')
-rw-r--r--Encoder/MessageDigestPasswordEncoder.php14
1 files changed, 9 insertions, 5 deletions
diff --git a/Encoder/MessageDigestPasswordEncoder.php b/Encoder/MessageDigestPasswordEncoder.php
index 4d0edd8..22303b6 100644
--- a/Encoder/MessageDigestPasswordEncoder.php
+++ b/Encoder/MessageDigestPasswordEncoder.php
@@ -25,10 +25,10 @@ class MessageDigestPasswordEncoder extends BasePasswordEncoder
* Constructor.
*
* @param string $algorithm The digest algorithm to use
- * @param Boolean $encodeHashAsBase64 Whether to base64 encode the password
+ * @param Boolean $encodeHashAsBase64 Whether to base64 encode the password hash
* @param integer $iterations The number of iterations to use to stretch the password
*/
- public function __construct($algorithm = 'sha1', $encodeHashAsBase64 = false, $iterations = 1)
+ public function __construct($algorithm = 'sha256', $encodeHashAsBase64 = false, $iterations = 1)
{
$this->algorithm = $algorithm;
$this->encodeHashAsBase64 = $encodeHashAsBase64;
@@ -40,12 +40,16 @@ class MessageDigestPasswordEncoder extends BasePasswordEncoder
*/
public function encodePassword($raw, $salt)
{
+ if (!in_array($this->algorithm, hash_algos(), true)) {
+ throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm));
+ }
+
$salted = $this->mergePasswordAndSalt($raw, $salt);
- $digest = call_user_func($this->algorithm, $salted);
+ $digest = hash($this->algorithm, $salted);
- // "stretch" the encoded value
+ // "stretch" hash
for ($i = 1; $i < $this->iterations; $i++) {
- $digest = call_user_func($this->algorithm, $digest);
+ $digest = hash($this->algorithm, $digest);
}
return $this->encodeHashAsBase64 ? base64_encode($digest) : $digest;