Skip to content

Instantly share code, notes, and snippets.

@jreinke
Created August 14, 2012 14:45
Show Gist options
  • Save jreinke/3349922 to your computer and use it in GitHub Desktop.
Save jreinke/3349922 to your computer and use it in GitHub Desktop.
Default password encoding in Silex micro-framework
<?php
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
$encoder = new MessageDigestPasswordEncoder();
echo $encoder->encodePassword('foo', '');
// 5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg==
@serweb-labs
Copy link

Fresh.

@sdmg15
Copy link

sdmg15 commented Mar 2, 2016

Hi
How to compare two encoded password using the same salt.
Thanks

@alejandroschmechel
Copy link

Thanks bro!

@emaV
Copy link

emaV commented Oct 24, 2016

Not sure if something changed but now with Silex 2.0.3 (Symfony 3.1.5) to get a password from the console (so using the framework and not Silex) to generate a password I have to use:

use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;

$encoder = new BCryptPasswordEncoder(13);
$pwd = 'sens';
$hash = $encoder->encodePassword($pwd, '');
echo "\n$pwd\n$hash\n";

The hash keeps changing but according Authenticating against a Database. Hashing a password it's ok as

A salt for each new password is generated automatically and need not be persisted. Since an encoded password contains the salt used to encode it, persisting the encoded password alone is `enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment