Permalink
Browse files

fixed Password

  • Loading branch information...
1 parent 533d2a4 commit eec127887a7ccd8138dda86e5a54159075664f38 @kolinger committed Jan 9, 2013
Showing with 15 additions and 6 deletions.
  1. +15 −6 Utils/Password.php
View
@@ -62,8 +62,9 @@ public function __construct($hash = NULL)
public function setPassword($password = NULL)
{
$this->salt = Strings::random();
- $this->password = $password === NULL ? Strings::random() : $password;
- return $this->password;
+ $password = $password === NULL ? Strings::random() : $password;
+ $this->password = hash($this->algorithm, $this->salt . $password);
+ return $password;
}
@@ -81,13 +82,20 @@ public function setAlgorithm($algorithm)
/**
+ * @param string $password
* @return string
*/
- public function getHash()
+ public function getHash($password = NULL)
{
$hash = $this->algorithm . self::DELIMITER
- . $this->salt . self::DELIMITER
- . hash($this->algorithm, $this->salt . $this->password);
+ . $this->salt . self::DELIMITER;
+
+ if ($password === NULL) {
+ $hash .= $this->password;
+ } else {
+ $hash .= hash($this->algorithm, $this->salt . $password);
+ }
+
return $hash;
}
@@ -117,7 +125,8 @@ public function compare($value)
if ($value instanceof Password) {
return $this->getHash() === $value->getHash();
} else {
- return $this->getHash() === $value;
+ dump($this->getHash(), $this->getHash($value));
+ return $this->getHash() === $this->getHash($value);
}
}

0 comments on commit eec1278

Please sign in to comment.