我创建了一个身份验证表单,当我尝试登录时,出现错误"凭据无效"。我用error.messageKey检查了,问题不是来自用户名,所以问题必须来自密码。
我到处看,我看不出有什么问题。你有什么想法吗?
提前致谢
security:
hide_user_not_found: false
encoders:
AppEntityUtilisateur:
algorithm: bcrypt
cost: 5
providers:
in_memory: { memory: ~ }
in_database:
entity:
class: AppEntityUtilisateur
property: mail
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
provider: in_database
form_login:
login_path: login
check_path: login
default_target_path: home
和登录.twig
<form action="{{ path('login') }}" method="POST">
<div class="form-group" id="formMail">
<label for="email">Email :</label>
<input type="email" class="form-control" id="email" placeholder="dupont@gmail.com" required name="_username">
<span class="" id="spanMail"></span>
<span class="" id="spanErrMail"></span>
</div>
<div class="form-group" id="formMdp">
<label for="pwd">Mot de passe :</label>
<input type="password" class="form-control" id="pwd" placeholder="******" required name="_password">
<span class="" id="spanMdp"></span>
<span class="" id="spanErrMdp"></span>
</div>
用户实体
/**
* @ORMEntity(repositoryClass="AppRepositoryUtilisateurRepository")
* @UniqueEntity(
* fields={"mail"},
* message="Adresse mail déjà utilisée")
*/
class Utilisateur implements UserInterface
{
/**
* @ORMId()
* @ORMGeneratedValue()
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=255)
*/
private $nom;
/**
* @ORMColumn(type="string", length=255)
*/
private $prenom;
/**
* @ORMColumn(type="string", length=255)
* @AssertEmail(
* message = "L'e-mail {{ value }} n'est pas valide ")
*/
private $mail;
/**
* @ORMColumn(type="string", length=255)
* @AssertLength(min="5", minMessage="Le mot de passe doit faire au moins 5 caractères")
*/
private $mdp;
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(string $prenom): self
{
$this->prenom = $prenom;
return $this;
}
public function getMail(): ?string
{
return $this->mail;
}
public function setMail(string $mail): self
{
$this->mail = $mail;
return $this;
}
public function getMdp(): ?string
{
return $this->mdp;
}
public function setMdp(string $mdp): self
{
$this->mdp = $mdp;
return $this;
}
public function getPassword(){}
public function getUsername(){
return $this->mail;
}
public function eraseCredentials(){}
public function getSalt(){
return '';
}
public function getRoles()
{
return ['ROLE_USER'];
}
}
我找到了我的神秘感。我使用自己的函数名称来获取电子邮件和密码。
我应该实现getUsername()和getPassword()。
public function getMdp(): ?string
{
return $this->mdp;
}
public function setMdp(string $mdp): self
{
$this->mdp = $mdp;
return $this;
}
public function getPassword(){
return $this->mdp;
}
public function getUsername(){
return $this->mail;
}