Security Can';t使用Symfony2登录
security.yml:Security Can';t使用Symfony2登录,security,symfony,Security,Symfony,security.yml: providers: main: entity: { class: Tg\UserBundle\Entity\User, property: username } encoders: Tg\UserBundle\Entity\User: sha512 在注册期间,我在我的管理器中设置了密码: $encoder = $this->encoder->getEncoder($user); $raw = $user
providers:
main:
entity: { class: Tg\UserBundle\Entity\User, property: username }
encoders:
Tg\UserBundle\Entity\User: sha512
在注册期间,我在我的管理器中设置了密码:
$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);
}
在我的用户实体中,我有基本的salt on构造:
$this->salt = md5(uniqid(null, true));
我在默认登录模板上收到错误:
提供的密码无效
Wtf?这不是一个确切的答案(我不明白为什么您的示例不起作用)。但我使用的是sha512 base64编码,该设置对我来说运行良好:
security:
encoders:
Acme\HelloBundle\Entity\User:
algorithm: sha512
encode_as_base64: true
iterations: 10
用户
类中的Salt初始化:
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
希望这能有所帮助。这并不是一个确切的答案(我不明白你的例子为什么不起作用)。但我使用的是sha512 base64编码,该设置对我来说运行良好:
security:
encoders:
Acme\HelloBundle\Entity\User:
algorithm: sha512
encode_as_base64: true
iterations: 10
用户
类中的Salt初始化:
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
希望这有帮助。我也遇到了这个错误。您需要确保密码字段可以支持sha512哈希大小。我认为教程将密码字段的默认大小设置为40。您需要将其扩展到更大的尺寸(125)。我也遇到了这个错误。您需要确保密码字段可以支持sha512哈希大小。我认为教程将密码字段的默认大小设置为40。您需要将其扩展到更大的大小(125)。这并不能解决问题,但使用您的salt使我更改了salt列的长度,唉,出现了错误,密码的长度太小。谢谢你引导我解决这个问题!这并没有解决问题,但使用您的salt使我更改了salt列的长度,唉,出现了错误,密码的长度太小了。谢谢你引导我解决这个问题!