[英]Can't log in with Symfony2
security.yml: 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? WTF?
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:
但是我使用的是sha512 base64编码的,此设置对我来说很好用:
security:
encoders:
Acme\HelloBundle\Entity\User:
algorithm: sha512
encode_as_base64: true
iterations: 10
Salt initialization in User
class: User
类中的Salt初始化:
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
Hope this helps. 希望这可以帮助。
I just hit this error as well. 我也碰到了这个错误。 You need to make sure you password field can support the sha512 hash size.
您需要确保您的密码字段可以支持sha512哈希大小。 I think the tutorials make the password field default to a size of 40. You need to extend this to a larger size (125).
我认为这些教程将密码字段的默认大小设置为40。您需要将其扩展为更大的大小(125)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.