Skip to content

Instantly share code, notes, and snippets.

@richsage
Created September 15, 2013 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richsage/6571186 to your computer and use it in GitHub Desktop.
Save richsage/6571186 to your computer and use it in GitHub Desktop.
<?php
namespace Acme\DemoBundle\Security\Encoder;
use Symfony\Component\Security\Core\Encoder\BasePasswordEncoder;
class MySQLPasswordEncoder extends BasePasswordEncoder
{
/**
* {@inheritdoc}
*/
public function encodePassword($raw, $salt)
{
return $this->doEncode($raw);
}
/**
* {@inheritdoc}
*/
public function isPasswordValid($encoded, $raw, $salt)
{
$pass2 = $this->doEncode($raw);
return $this->comparePasswords($encoded, $pass2);
}
/**
* Do the actual encoding
* @param $input
* @return string
*/
protected function doEncode($input)
{
$sha1_stage1 = sha1($input, true);
$output = sha1($sha1_stage1, false);
return "*" . strtoupper($output);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment