0

I'm having an issue with the UserAuthenticationProvider. I'm using Doctrine persistence and I'm getting the Bad credentials error every time, even if the user is valid.

the database contains the fields: username, password, salt, *date_created*, *date_modified* that are populated just fine on register.

After a bit of research I found out that the checkAuthentication($user, $token); from UserAuthenticationProvider fails and the Bad credentials error is thrown afterwards.

routing.yml:

login:
    path:     /auth/login
    defaults: { _controller: WebsiteStaticBundle:Auth:login }

check_login:
    path:     /auth/do_login
    defaults: { _controller: WebsiteStaticBundle:Auth:doLogin }

security.yml:

security:

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

providers:
    administrators:
        entity: { class: AuthBundle:Account }

encoders:
    API\AuthBundle\Entity\Account:
        algorithm: sha1
        iterations: 1
        encode_as_base64: false

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false

    login:
        pattern:  ^/demo/secured/login$
        security: false

    secured_area:
        pattern:    ^/
        anonymous: ~
        form_login:
            login_path:   login
            check_path:   check_login

        logout:
            path:   /logout
            target: /

access_control:
    - { path: ^/demo/secured/hello/admin/, roles: ROLE_ADMIN }
    - { path: ^/restricted, roles: ROLE_ADMIN }
    - { path: ^/dashboard, roles: ROLE_ADMIN }

and the 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);
        $session->remove(SecurityContext::AUTHENTICATION_ERROR);
    }

    $form = $this->createForm(new AccountType(), null, array(

    ));


    return array(
        'login_form' => $form->createView(),
        'page_title' => 'Login',
        // last username entered by the user
        'last_username' => $session->get(SecurityContext::LAST_USERNAME),
        'error'         => $error,
    );
}

and the logs:

[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2013-11-08 23:30:53] request.INFO: Matched route "check_login" (parameters: "_controller": "Website\StaticBundle\Controller\AuthController::doLoginAction", "_route": "check_login") [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
[2013-11-08 23:30:53] doctrine.DEBUG: SELECT a0_.account_id AS account_id0, a0_.username AS username1, a0_.password AS password2, a0_.salt AS salt3, a0_.date_created AS date_created4, a0_.date_modified AS date_modified5, a0_.status_id AS status_id6 FROM account a0_ WHERE a0_.username = ? ["alex"] []
[2013-11-08 23:30:53] security.INFO: Authentication request failed: Bad credentials [] []
[2013-11-08 23:30:53] security.DEBUG: Redirecting to login [] []
[2013-11-08 23:30:53] event.DEBUG: Listener "Symfony\Component\Security\Http\Firewall::onKernelRequest" stopped propagation of the event "kernel.request". [] []
[2013-11-08 23:30:53] event.DEBUG: Listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest" was not called for event "kernel.request". [] []
[2013-11-08 23:30:53] event.DEBUG: Listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger" was not called for event "kernel.request". [] []
[2013-11-08 23:30:53] event.DEBUG: Listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger" was not called for event "kernel.request". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse". [] []
[2013-11-08 23:30:53] security.DEBUG: Write SecurityContext in the session [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:53] event.DEBUG: Notified event "kernel.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2013-11-08 23:30:54] request.INFO: Matched route "login" (parameters: "_controller": "Website\StaticBundle\Controller\AuthController::loginAction", "_route": "login") [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
[2013-11-08 23:30:54] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Acme\DemoBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.view" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelView". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2013-11-08 23:30:54] request.INFO: Matched route "navigation" (parameters: "_controller": "Website\StaticBundle\Controller\AuthController::navigationAction", "_route": "navigation") [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Acme\DemoBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.view" to listener "closure". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.view" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelView". [] []
[2013-11-08 23:30:54] event.DEBUG: Listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelView" stopped propagation of the event "kernel.view". [] []
[2013-11-08 23:30:54] event.DEBUG: Listener "closure" stopped propagation of the event "kernel.view". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelView" stopped propagation of the event "kernel.view". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse". [] []
[2013-11-08 23:30:54] security.DEBUG: Write SecurityContext in the session [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:54] event.DEBUG: Notified event "kernel.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2013-11-08 23:30:56] request.INFO: Matched route "_wdt" (parameters: "_controller": "web_profiler.controller.profiler:toolbarAction", "token": "e51eae", "_route": "_wdt") [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.controller" to listener "Acme\DemoBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse". [] []
[2013-11-08 23:30:56] event.DEBUG: Notified event "kernel.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate". [] []

the action that handles the registration:

...
if ($form->isValid()) {

    $data = $form->getData();

    /**
     * Account
     */
    $account->setUsername($data->getAccount()->getUsername());

    // Password
    $factory = $this->get('security.encoder_factory');

    $encoder = $factory->getEncoder($account);
    $password = $encoder->encodePassword($data->getAccount()->getPassword(), $account->getSalt());

    $account->setPassword($password);
    $account->setSalt($data->getAccount()->getSalt());

    $now = new \DateTime('now');
    $account->setDateCreated($now);
    $account->setDateModified($now);

    /**
     * Consumer account
     */
    $consumerAccount->setAccount($account);
    $consumerAccount->setFirstName($data->getFirstName());
    $consumerAccount->setLastName($data->getLastName());
    $consumerAccount->setGender($data->getGender());

    $em = $this->getDoctrine()->getManager();

    $em->persist($account);
    $em->persist($consumerAccount);

    $em->flush();

    $this->get('session')->getFlashBag()->add(
        'notice',
        'Successfully registered!'
    );

    return $this->redirect($this->generateUrl('login'));
}

The query is fine and the user is extracted as expected, so I think the problem is not in the actual Account entity, but most likely in the configuration.

Any help will be greatly appreciated. Thank you.

2
  • 1
    Can you edit your question to include more of your security.yml, if not all of it? Most important here is the encoders, providers and access_control sections. Thanks. Commented Nov 9, 2013 at 10:36
  • 1
    If the user is found, then the problem is with the authentication -> that means, the password is not good. What you should do at the first time, check in the DB, if your supposed password is right, i mean run somewhere the sha1($password.'{'.$salt.'}') computation, and check if they are the right ones, or the DB field length is enough and didn't cut down some digits from the end. Commented Nov 17, 2013 at 21:10

1 Answer 1

1
+50
[2013-11-08 23:30:53] doctrine.DEBUG: SELECT a0_.account_id AS account_id0, a0_.username AS username1, a0_.password AS password2, a0_.salt AS salt3, a0_.date_created AS date_created4, a0_.date_modified AS date_modified5, a0_.status_id AS status_id6 FROM account a0_ WHERE a0_.username = ? ["alex"] []
[2013-11-08 23:30:53] security.INFO: Authentication request failed: Bad credentials [] []

You should check if this query returns a result (using the profiler). If so, the Bad credentials means that the password entered isn't correct, or, more likely, the encrypted version stored in the db isn't what you think it is.

Make sure you use the configured encoder to encode the users password:

$factory = $this->get('security.encoder_factory');
$user = new Acme\UserBundle\Entity\User();

$encoder = $factory->getEncoder($user);
$password = $encoder->encodePassword('ryanpass', $user->getSalt());
$user->setPassword($password);

When this issue is resolved, there's a chance you still won't be logged in to the "secured area". This is because your login form/page and the "secured area" use different firewalls. You've logged in to one firewall, but not to the other.

Try removing the firewall login, and add this to access_control:

- { path: ^/demo/secured/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }

UPDATE

You can set hide_user_not_found to false under security in your config to have the provider throw meaningful exceptions. You'll have a better indication of what went wrong.

If the problem is indeed the password, you should start debugging the DaoAuthenticationProvider here. Dump the passwords it's comparing to see what's really going on.

Sign up to request clarification or add additional context in comments.

4 Comments

sorry for the delay, I'm doing exactly what you suggested (for the encoder for the users password) and it still doesn't work. I updated the question with the action responsible for the registration
and yes, the query returns the user I need. I guess something must be incorrect with the password/salt validation.
Updated my answer on how you can check the passwords.
Thank you, the update helped a lot. I was getting bad credentials because the password field in the database had a smaller size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.