Problème avec le login

Par LECARROU, il y a 7 ans


EDIT

je pense que c'est effectivement la fonction de hashage bcrypt qui ne fonctionne pas
lorsque je passe en plaintext, le login fonctionne
j'ai essayé en SHA512 pour voir en essayant de décrypte en ligne et il ne me trouve aucune correspondance...

Bonjour,

Voila je rencontre un petit problème avec mon code.
J'ai créé un formulaire de connexion à partir d'une entité Abonne que j'ai créé et lié à ma base MySql (MAMP).
je peux enregistrer mes des abonnes dans la tables Abonne et j'encode le mot de passe à l'aide de bcrypt.
mais je ne parviens pas à me connecter avec les comptes que je créé ; tout se passe comme si le mot de passe n'était pas reconnu et j'ai le message "Invalid credentials."

security.yalm

security: encoders: App\Entity\Abonne: algorithm: bcrypt # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers providers: in_memory: { memory: ~ } in_database: entity: class: App\Entity\Abonne property: email firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false main: anonymous: true provider: in_database form_login: login_path: security_login check_path: security_login

Abonne.php

<?php namespace App\Entity; use Serializable; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * @ORM\Entity(repositoryClass="App\Repository\AbonneRepository") * @UniqueEntity( * fields={"email"}, * message= "L'email que vous avez tapé est déjà utilisé" * ) */ class Abonne implements UserInterface { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $nomAbonne; /** * @ORM\Column(type="string", length=255) */ private $PrenomAbonne; /** * @ORM\Column(type="string", length=20) * @Assert\Length(min="8", minMessage="Votre mot de passe doit faire 8 caractères minimum") */ private $motDePasseAbonne; /** * @Assert\EqualTo(propertyPath="motDePasseAbonne", message="Mot de passe non confirmé") */ public $confirmMotDePasseAbonne; /** * @ORM\Column(type="string", length=255) * @Assert\Email() */ private $email; public function getId(): ?int { return $this->id; } public function getNomAbonne(): ?string { return $this->nomAbonne; } public function setNomAbonne(string $nomAbonne): self { $this->nomAbonne = $nomAbonne; return $this; } public function getPrenomAbonne(): ?string { return $this->PrenomAbonne; } public function setPrenomAbonne(string $PrenomAbonne): self { $this->PrenomAbonne = $PrenomAbonne; return $this; } public function getMotDePasseAbonne(): ?string { return $this->motDePasseAbonne; } public function setMotDePasseAbonne(string $motDePasseAbonne): self { $this->motDePasseAbonne = $motDePasseAbonne; return $this; } public function getEmail(): ?string { return $this->email; } public function setEmail(string $email): self { $this->email = $email; return $this; } //méthode à implémenter public function getPassword() {} public function getUsername() {} public function eraseCredentials(){} public function getSalt() { return null; } public function getRoles() { return['ROLE_USER']; } }

SecurityController.php

<?php namespace App\Controller; use App\Entity\Abonne; use App\Form\RegistrationType; use Symfony\Component\HttpFoundation\Request; use Doctrine\Common\Persistence\ObjectManager; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; class SecurityController extends AbstractController { /** * @Route("/inscription", name="security_registration") */ public function registration(Request $request, ObjectManager $manager,UserPasswordEncoderInterface $encoder) { $abonne = new Abonne(); $form = $this->createForm(RegistrationType::class, $abonne); $form->handleRequest($request); if($form->isSubmitted() && $form->isValid()){ $hash = $encoder->encodePassword($abonne, $abonne->getMotDePasseAbonne()); $abonne->setMotDePasseAbonne($hash); $manager->persist($abonne); $manager->flush(); return $this->redirectToRoute('security_login'); } return $this->render('security/registration.html.twig', [ 'form' => $form->createView() ]); } /** * @Route("/connexion", name="security_login") */ public function login(Request $request, AuthenticationUtils $authenticationUtils){ // get the login error if there is one $error = $authenticationUtils->getLastAuthenticationError(); // last username entered by the user $lastUsername = $authenticationUtils->getLastUsername(); return $this-> render('security/login.html.twig', array( 'last_username' => $lastUsername, 'error' => $error,)); } }

login.html.twig

{% extends 'base.html.twig' %} {% block body %} <h1>Connexion</h1> {% if error %} <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div> {% endif %} <form action="{{ path('security_login') }}" method="post"> <div class="form-group"> <input placeholder="Adresse email" required name="_username" value="{{ last_username }}" type="text" class="form-control"> </div> <div class="form-group"> <input placeholder="Mot de passe" required name="_password" type="password" class="form-control"> </div> <div class="form-group"> <button class="btn btn-success">Connexion</button> </div> </form> {% endblock %}

Aucune réponse