Skip to content

Instantly share code, notes, and snippets.

@intellix
Created July 28, 2013 22:42
Show Gist options
  • Save intellix/6100583 to your computer and use it in GitHub Desktop.
Save intellix/6100583 to your computer and use it in GitHub Desktop.
Bcrypt passwords with ZF2 + Doctrine ORM Module
<?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()
}
<?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