Created
July 28, 2013 22:42
-
-
Save intellix/6100583 to your computer and use it in GitHub Desktop.
Bcrypt passwords with ZF2 + Doctrine ORM Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Service; | |
use Zend\Crypt\Password\Bcrypt; | |
use Application\Entity; | |
class UserService | |
{ | |
/** | |
* Static function for checking hashed password (as required by Doctrine) | |
* @param Entity\Account $account The identity object | |
* @param string $passwordGiven Password provided by the user, to verify | |
* @return boolean If the password was correct or not | |
*/ | |
public static function verifyHashedPassword(Entity\Account $account, $passwordGiven) | |
{ | |
$bcrypt = new Bcrypt; | |
return $bcrypt->verify($passwordGiven, $account->getPassword()); | |
} | |
// Other stuff like register() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'doctrine' => array( | |
'authentication' => array( | |
'orm_default' => array( | |
'objectManager' => 'Doctrine\ORM\EntityManager', | |
'identityClass' => 'Application\Entity\Account', | |
'identity_property' => 'email', | |
'credential_property' => 'password', | |
'credential_callable' => 'Application\Service\UserService::verifyHashedPassword' | |
), | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment