Skip to content

Instantly share code, notes, and snippets.

@alexandresalome
Created January 26, 2015 18:16
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 alexandresalome/7da127b2547945aad450 to your computer and use it in GitHub Desktop.
Save alexandresalome/7da127b2547945aad450 to your computer and use it in GitHub Desktop.
Demonstration of password encoder
<?php
<<<CONFIG
packages:
- symfony/security
CONFIG;
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder;
# $encoder = new MessageDigestPasswordEncoder();
$encoder = new PlaintextPasswordEncoder();
$password = 'toto';
$passwordToValid = 'toto';
$salt = md5(mt_rand());
$hashed = $encoder->encodePassword($password, $salt);
$isValid = $encoder->isPasswordValid($hashed, $passwordToValid, $salt);
echo $isValid ? 'OK' : 'KO';
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment