Created
November 18, 2012 17:14
-
-
Save baldurrensch/4106308 to your computer and use it in GitHub Desktop.
How to use Phpass in Symfony
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 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); | |
} | |
} |
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
security: | |
encoders: | |
Acme\TestBundle\Security\User\AuthenticatedUser: | |
id: acme.security.phpass_encoder |
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
<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