Created
June 1, 2015 07:15
-
-
Save icambridge/5300b2a609a80492b657 to your computer and use it in GitHub Desktop.
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
Icambridge\Entity\User: | |
id: encoder.super_duper_silly |
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
<service id="encoder.super_duper_silly" class="Icambridge\Encoder\SuperDuperSillyEncoder" /> |
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
bcrypt: | |
algorithm: bcrypt |
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
Icambridge\Entity\InsecureUser: | |
algorithm: plaintext | |
bcrypt: | |
algorithm: bcrypt |
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 Icambridge\Encoder; | |
class User implements EncoderAwareInterface | |
{ | |
public function getEncoderName() | |
{ | |
return "bcrypt"; | |
} | |
} |
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 Icambridge\Encoder; | |
use Symfony\Component\Security\Core\Exception\BadCredentialsException; | |
use Symfony\Component\Security\Core\Encoder\BasePasswordEncoder | |
/** | |
* A super duper silly password encoder, no one should ever use! | |
*/ | |
class SuperDuperSillyEncoder extends BasePasswordEncoder | |
{ | |
private $ignorePasswordCase; | |
public function encodePassword($raw, $salt) | |
{ | |
if ($this->isPasswordTooLong($raw)) { | |
throw new BadCredentialsException('Invalid password.'); | |
} | |
$rawMd5 = md5($raw); | |
$saltSha = sha1($salt); | |
$encodableString = $this->mergePasswordAndSalt($rawmd5, $saltSha); | |
$encodedString = $encodableString . $encodableString[0] . $encodableString[1]; | |
return $encodedString; | |
} | |
public function isPasswordValid($encoded, $raw, $salt) | |
{ | |
if ($this->isPasswordTooLong($raw)) { | |
return false; | |
} | |
$pass2 = $this->encodePassword($raw, $salt); | |
if (!$this->ignorePasswordCase) { | |
return $this->comparePasswords($encoded, $pass2); | |
} | |
return $this->comparePasswords(strtolower($encoded), strtolower($pass2)); | |
} | |
} |
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
$encoder = $encoderFactory->getEncoder('bcrypt'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment