gpt4 book ai didi

symfony - 在 Symfony2 中验证密码

转载 作者:行者123 更新时间:2023-12-04 03:30:02 24 4
gpt4 key购买 nike

我正在尝试在 Symfony2 中整合更改密码功能。我有一个“当前密码”字段、一个“新密码”字段和一个“确认新密码”字段,而我目前关注的部分是验证“当前密码”字段。

(顺便说一句,我现在意识到像 FOSUserBundle 这样的东西可以为我处理很多这些事情,但是我已经根据 Symfony 官方文档构建了我的身份验证系统,我没有时间现在重做我所有的验证码。)

我想象/希望我能做的是创建一个验证回调,它说这样的话:

// Entity/User.php

public function currentPasswordIsValid(ExecutionContext $context)
{
$currentPassword = $whatever; // whatever the user submitted as their current password
$factory = $this->get('security.encoder_factory'); // Getting the factory this way doesn't work in this context.
$encoder = $factory->getEncoder($this);
$encryptedCurrentPassword = $encoder->encodePassword($this->getPassword(), $this->getSalt());

if ($encyptedCurrentPassword != $this->getPassword() {
$context->addViolation('Current password is not valid', array(), null);
}
}

正如您在我的评论中看到的那样,上述代码不起作用至少有几个原因。我只会发布有关这些特定问题的具体问题,但也许我完全是在找错树。这就是为什么我要问整体问题。

那么,如何验证用户的密码呢?

最佳答案

我最终割断了快死结。我绕过了 Symfony 的所有表单内容,并在 Controller 中完成了所有逻辑。

关于symfony - 在 Symfony2 中验证密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9965795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com