Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Authentification probleme Symfony 4 (Security component )

$
0
0

I have a little problem with my Symfony 4 login page. When users submits the form, the following error appears:

Notice: A non well formed numeric value encountered

and yet when I go to the data base the login is there, the password is there too (hash it out of course) and despite this it doesn't work.

and sometimes it starts working but only when env=dev but when env=prod there is an error 500

this is the controller

<?php

namespace App\Controller ;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\User ;

//Class pour authentification
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils ;


class SecurityController extends AbstractController
{

  /**
  * @Route("/login" , name="login")
  */
  public function login(AuthenticationUtils $authentication)
  {
    $error = $authentication->getLastAuthenticationError();

    $lastUsername = $authentication->getLastUsername();

    return $this->render('Authentification/login.html.twig' ,[
      'error'         => $error,
      'last_username' => $lastUsername,
      ]) ;
  }
}

security.yaml file:

security:
    providers:
        from_database:
            entity:
                class: App\Entity\User
                property: username

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: lazy
            form_login:
                remember_me: true
                check_path: /login

            logout :
                path: /logout
                target: /

    access_control: 
        - { path: ^/admin, roles: ROLE_ADMIN }

    encoders:
        App\Entity\User:
          algorithm: bcrypt
          cost :  14

form login :

{% extends 'baseConnection.html.twig' %}

{% block title %}Se Connecter{% endblock %}

{% block body %}
<div class="container">

  <h3>Page de Connection de l'application CUMA le PROGRES</h3>

  <p class="btn float-right color-br" onclick="window.history.back();">Retour</p>

  {% if error %}

  <div class="alert alert-danger">

    {% if error %}

    {{ error.messageKey | trans(error.messagedata ,  'security') }}

    {% endif %}

  </div>

  {% endif %}

  <form  action="{{  path('login')}}" method="post">
    <div class="form-group">
      <label for="username">Nom d'utilisateur</label>
      <input type="text" id="username" name="_username" class="form-control" placeholder="Vôtre nom d'utilisateur est du style:    Prénom.Nom" value="{{ last_username }}">
    </div>
      <div class="form-group">

          <label for="password">Mot de passe</label>

          <input type="password" id="password" name="_password" class="form-control" placeholder="Vôtre mot de passe ..... ( en cas d'oublie aller voir Fabien ABISUR )">
      </div>
      <button type="submit" class="btn color-br">Se Connecter</button>
    </form>
</div>
{% endblock %}

Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>