Skip to content

Commit

Permalink
Fixes security issue on handling a failed password_hash (#5)
Browse files Browse the repository at this point in the history
* Fix #4 - Add check for unsuccessful hash

* Remove unnecessary `return` statement on `__construct`
  • Loading branch information
NigelGreenway authored Jun 17, 2016
1 parent 49bd1af commit 73d623f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Exception/InactivePassException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ final class InactivePassException extends Exception
/** Class constructor */
public function __construct()
{
return parent::__construct('Inactive Pass');
parent::__construct('Inactive Pass');
}
}
2 changes: 1 addition & 1 deletion lib/Exception/InvalidPasswordException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ final class InvalidPasswordException extends Exception
/** Class Constructor */
public function __construct()
{
return parent::__construct('An invalid password as been given');
parent::__construct('An invalid password as been given');
}
}
12 changes: 10 additions & 2 deletions lib/Handler/BasicPasswordHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ private function __construct($hash)
$this->hash = $hash;
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*
* @throws \RuntimeException
*/
public static function hash($password, array $options = [])
{
$hash = password_hash($password, PASSWORD_DEFAULT, $options);

return new self($hash);
if ($hash !== false) {
return new self($hash);
}

throw new \RuntimeException('Unsuccessful `password_hash` function call');
}

/** {@inheritDoc} */
Expand Down

0 comments on commit 73d623f

Please sign in to comment.