您好,我正在尝试使用 Symfony2 和数据库表登录,并在 md5 中使用没有盐田的密码进行登录。我有很多用户,我无法更改它。
当我使用无效电子邮件发送表单时,登录似乎工作正常,它返回消息"凭据错误"。但是当我发送带有良好电子邮件的表单时,它说"提供的密码无效"。
怎么了?
我配置防火墙:
security:
encoders:
UsuariBackendBundleEntityUsuari:
algorithm: md5
在 Usuari 实体中实现用户界面,无需盐
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 MesBackendBundleController;
use SymfonyBundleFrameworkBundleControllerController;
use SymfonyComponentSecurityCoreSecurityContext;
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,
));
}
}
?>
将algorithm: sha1
更改为 algorithm: md5
。
我也有类似的情况。我所做的是我创建了单独的编码器,以便旧用户可以使用旧算法登录,而新用户可以使用symfony的默认编码器获得更安全的密码。
我在这里发布了一个非常广泛的答案
Thomas,这个解决方案似乎工作正常,但它更复杂。
最后,我决定使用其他编码函数和盐字段从数据库中重新生成所有密码。我将向所有用户发送一封电子邮件,其中包含允许这些用户更改密码的链接