php - Not able to login using a login form in Symfony 3.1 -


i've been following tutorial on symfony website (http://symfony.com/doc/current/security.html) add login symfony 3.1 project. works fine http basic authentication, when add form_login using tutorial here (http://symfony.com/doc/current/security/form_login_setup.html) keeps redirecting login page , not logging in.

here security.yml:

security: providers:     in_memory:         memory:             users:                 ryan:                      password: ryanpass                     roles: 'role_user'                  admin:                     password: kitten                     roles: 'role_admin'  encoders:     symfony\component\security\core\user\user: plaintext  firewalls:     login_firewall:        anonymous: ~     dev:         pattern: ^/(_(profiler|wdt)|css|images|js)/         security: false      main:         provider: in_memory         form_login:              login_path: /login             check_path: /login_check         logout: ~   access_control: - { path: ^/login, roles: is_authenticated_anonymously } - { path: ^/, roles: role_user } 

security controller:

class securitycontroller extends controller { /**  * @route("/login", name="login")  */   public function loginaction(request $request)    {      $authenticationutils = $this->get('security.authentication_utils');      // login error if there 1     $error = $authenticationutils->getlastauthenticationerror();      // last username entered user     $lastusername = $authenticationutils->getlastusername();      return $this->render(         'security/login.html.twig',         array(             // last username entered user             'last_username' => $lastusername,             'error'         => $error,         )     );  }  /**  * @route("/login_check", name="login_check")  */ public function logincheckaction(request $request) {     ; } 

login.html.twig:

{% extends 'base.html.twig' %} {% block body %}     <div id="login_form"> {% if error %}     <div>{{ error.messagekey|trans(error.messagedata, 'security')  }}</div> {% endif %}      <form action="{{ path('login') }}" method="post">         <p><label for="username">username:</label>             <input type="text" id="username" name="_username" value="{{ last_username }}" /></p>          <p><label for="password">password:</label>             <input type="password" id="password" name="_password" /></p>          {#             if want control url user             redirected on success (more details below)             <input type="hidden" name="_target_path" value="/account" />         #}          <p><button type="submit">login</button></p>     </form> </div>  {% endblock %} 

thanks @cerad put encoders section above providers , removed firewall login

security now:

security:   encoders:      symfony\component\security\core\user\user: plaintext   providers:      in_memory:        memory:           users:             ryan:                  password: ryanpass                 roles: 'role_user'               admin:                 password: kitten                 roles: 'role_admin'      firewalls:     dev:       pattern: ^/(_(profiler|wdt)|css|images|js)/       security: false      main:      form_login:          login_path: /login         check_path: /login_check      logout: ~     access_control:     - { path: ^/login, roles: is_authenticated_anonymously }     - { path: ^/, roles: role_user } 

the login page anonymous via access_control list instead of firewall rule


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -