您好,我正在尝试使用 Symfony2 和数据库表登录,密码在 md5 中,没有盐字段。我有很多用户,我无法更改它。
当我发送带有无效电子邮件的表单时,登录似乎工作正常,它返回消息正确“凭据错误”。但是当我发送带有良好电子邮件的表格时,它会显示“提供的密码无效”。
怎么了?
我配置防火墙:
security:
    encoders:
        Usuari\BackendBundle\Entity\Usuari:
            algorithm: md5
在 Usuari 实体中实现 UserInterface,不加盐
    public function getUsername()
    {
        return $this->email;
    }
    public function getSalt() { 
        return '';
    }
    public function getPassword()
    {
        return $this->clau;
    }
    public function getRoles()
    {
        return array('ROLE_ADMIN');
    }
    public function eraseCredentials() { }
    public function equals(UserInterface $user)
    {
        return $this->email === $user->getUsername();
    }
和 /login 路由的安全控制:
namespace Mes\BackendBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
    class SecurityController extends Controller
    {
        public function loginAction()
        {
            $request = $this->getRequest();
            $session = $request->getSession();
            // get the login error if there is one
            if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
                $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
            } else {
                $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
            }
            return $this->render('MeBackendBundle:Security:login.html.twig', array(
                // last username entered by the user
                'last_username' => $session->get(SecurityContext::LAST_USERNAME),
                'error'         => $error,
            ));
        }
    }
    ?>