Skip to content

Instantly share code, notes, and snippets.

@baldurrensch
Created November 18, 2012 17:14
Show Gist options
  • Save baldurrensch/4106308 to your computer and use it in GitHub Desktop.
Save baldurrensch/4106308 to your computer and use it in GitHub Desktop.
How to use Phpass in Symfony
<?php
namespace Acme\DemoBundle\Security\Service;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
use Hautelook\Phpass\PasswordHash;
/**
* A password encoder that uses Phpass for encoding
*
* @author Baldur Rensch <brensch@gmail.com>
*/
class PhpassEncoder implements PasswordEncoderInterface
{
public function encodePassword($raw, $salt)
{
$hasher = new PasswordHash(8, false);
$hashedPassword = $hasher->hashPassword($raw);
return $hashedPassword;
}
public function isPasswordValid($encoded, $raw, $salt)
{
$hasher = new PasswordHash(8, false);
return $hasher->CheckPassword($raw, $encoded);
}
}
security:
encoders:
Acme\TestBundle\Security\User\AuthenticatedUser:
id: acme.security.phpass_encoder
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="acme.security.phpass_encoder" class="Acme\DemoBundle\Security\Service\PhpassEncoder" />
</services>
</container>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment