我是 Symfony2 的新手,我可能有一个关于在数据库中编码用户密码的简单问题。
我想以这种方式编码并存储在数据库中我的用户密码:
encoded_password = salt . sha1 ( salt . raw_password )
我找到了各种编码器(sha1、sha512、明文),我看到我的数据库 raw_password{salt} 中有明文,但我仍然对 Symfony2 中的 signin/login/getSalt() 方法感到不舒服。
如果您可以帮我解决这个问题(请假设我不想使用现有的用户管理包,我想制作自己的包),那就太棒了!
Thanks
EDIT:
我可以在我的signinAction()中做到这一点:
$salt = substr(md5(time()),0,10);
$pwd = $encoder->encodePassword($user->getPassword(), $salt);
$user->setPassword($salt.$pwd);
我可以在 getSalt() 中做到这一点:
return substr($this->password,0,10);
但我目前在我的 loginAction() 中只有这个:(参见此处:http://symfony.com/doc/current/book/security.html http://symfony.com/doc/current/book/security.html)
// src/Acme/SecurityBundle/Controller/Main;
namespace Acme\SecurityBundle\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('AcmeSecurityBundle:Security:login.html.twig', array(
// last username entered by the user
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
}
}
我如何告诉 Symfony2 在登录操作期间按照我需要的方式检查密码? (目前正在执行encode(password,salt)而不是salt.encode(password,salt)