Skip to content
Browse files

added default secret variable

  • Loading branch information...
1 parent 586a407 commit 321ac17f1c3014efb22fb88040f0cb1320a5e6c0 @trumtomte committed Apr 23, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 cloudlib/helpers/Hash.php
View
12 cloudlib/helpers/Hash.php
@@ -20,6 +20,14 @@
class Hash
{
/**
+ * Default secret to be used with hashing
+ *
+ * @access public
+ * @var string
+ */
+ public static $secret = null;
+
+ /**
* Constructor
*
* @access public
@@ -44,6 +52,8 @@ public static function create($value, $salt, $secret, $rounds = 12)
throw new InvalidArgumentException('The number of rounds has to be between 4-31');
}
+ $secret = (static::$secret) ? static::$secret : $secret;
+
$salt = sprintf('$2a$%02d$%s', $rounds, substr(base64_encode(sha1($salt . $secret)), 0, 22));
return substr(crypt($value, $salt), 7);
@@ -62,6 +72,8 @@ public static function create($value, $salt, $secret, $rounds = 12)
*/
public static function compare($hash, $value, $salt, $secret, $rounds = 12)
{
+ $secret = (static::$secret) ? static::$secret : $secret;
+
return (bool) (($new = static::create($value, $salt, $secret, $rounds)) == $hash);
}
}

0 comments on commit 321ac17

Please sign in to comment.
Something went wrong with that request. Please try again.