こんにちは私は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,
));
}
}
?>