Reputation: 17282
security.yml:
providers:
main:
entity: { class: Tg\UserBundle\Entity\User, property: username }
encoders:
Tg\UserBundle\Entity\User: sha512
In my manager during registration I set the password:
$encoder = $this->encoder->getEncoder($user);
$raw = $user->getPassword();
$salt = $user->getSalt();
$encoded = $encoder->encodePassword($raw, $salt);
if (!$encoder->isPasswordValid($encoded, $raw, $salt)) {
throw new \Exception('Password incorrectly encoded during user registration', 428);
} else {
$user->setPassword($encoded);
}
In my User entity I have the basic salt on construct:
$this->salt = md5(uniqid(null, true));
I receive error on default login template:
The presented password is invalid.
Wtf?
Upvotes: 1
Views: 1209
Reputation: 919
I just hit this error as well. You need to make sure you password field can support the sha512 hash size. I think the tutorials make the password field default to a size of 40. You need to extend this to a larger size (125).
Upvotes: 0
Reputation: 48899
This is not exactly an answer (i can't figure out why you r example is not working). But I'm using sha512 base64 encoded and this setup is working fine for me:
security:
encoders:
Acme\HelloBundle\Entity\User:
algorithm: sha512
encode_as_base64: true
iterations: 10
Salt initialization in User
class:
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
Hope this helps.
Upvotes: 1