Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7778573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:25:56+00:00 2026-06-01T18:25:56+00:00

This is my Entity: <?php namespace Trade\TradeBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as

  • 0

This is my Entity:

<?php

namespace Trade\TradeBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * @ORM\Entity(repositoryClass = "Trade\TradeBundle\Repository\UserRepository")
 * @ORM\Table(name = "user")
 * @UniqueEntity(fields = "username", message = "The username already exists.")
 */
class User implements UserInterface
{
/**
 * @ORM\id
 * @ORM\Column(name = "id", type = "integer")
 * @ORM\GeneratedValue(strategy = "AUTO")
 */
protected $id;

/**
 * @ORM\Column(name = "username", type = "string", length = 20, unique = true)
 *
 * @Assert\NotBlank(
 *      message = "The username cannot be blank."
 * )
 */
protected $username;

/**
 * @ORM\Column(name = "password", type = "string", length = 40)
 *
 * @Assert\NotBlank(
 *      message = "The password cannot be blank."
 * )
 * @Assert\MinLength(
 *      limit = 8,
 *      message = "The password '{{ value }}' is too short. It should have {{ limit }} characters or more."
 * )
 * @Assert\MaxLength(
 *      limit = 16,
 *      message = "The password '{{ value }}' is too long. It should have {{ limit }} characters or less."
 * )
 */
protected $password;

/**
 * @ORM\Column(type = "string", length = 40)
 */
protected $salt;

public function __construct()
{
    $this->salt = md5(uniqid(null, true));
}

/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

/**
 * Set username
 *
 * @param string $username
 */
public function setUsername($username)
{
    $this->username = $username;
}

/**
 * Get username
 *
 * @return string
 */
public function getUsername()
{
    return $this->username;
}

/**
 * Set password
 *
 * @param string $password
 */
public function setPassword($password)
{
    $this->password = $password;
}

/**
 * Get password
 *
 * @return string
 */
public function getPassword()
{
    return $this->password;
}

public function getSalt()
{
    return $this->salt;
}

public function getRoles()
{
    return array('ROLE_USER');
}

public function eraseCredentials()
{
}

public function equals(UserInterface $user)
{
    return $this->username === $user->getUsername();
}
}

This is my Repository:

<?php

namespace Trade\TradeBundle\Repository;

use Doctrine\ORM\EntityRepository;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * UserRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class UserRepository extends EntityRepository implements UserProviderInterface
{
public function loadUserByUsername($username)
{
    return $this->getEntityManager()->findOneByUsername($username);
}

public function refreshUser(UserInterface $user)
{
    return $this->loadUserByUsername($user->getUsername());
}

public function supportsClass($class)
{
    return $class === 'Trade\TradeBundle\Entity\User';
}
}

This is security.yml:

security:
    encoders:
        Trade\TradeBundle\Entity\User:
            algorithm: sha1
            encode_as_base64: false
            iterations: 1

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

providers:
    main:
        entity: { class: TradeTradeBundle:User, property: username }

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

    secured_area:
        pattern:    ^/
        form_login:
            check_path: /account/signin_check
            login_path: /account/signin
        logout:
            path:   /account/signout
            target: /
        anonymous: ~

access_control:
    - { path: ^/account/signin, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/account, roles: ROLE_USER }
    - { path: ^/admin, roles: ROLE_ADMIN }

This is my Controller action:

/**
 * @Route("/account/signin", name = "account_signin")
 * @Route("/account/signin_check", name = "account_signin_check")
 * @Method({"GET", "POST"})
 */
public function signInAction()
{
    $request = $this->getRequest();
    $session = $request->getSession();

    $user = new \Trade\TradeBundle\Entity\User();
    $form = $this->createForm(new \Trade\TradeBundle\Form\Type\UserType(), $user);

    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);
    }

    return $this->render('TradeTradeBundle:Account:signin.html.twig', array('form' => $form->createView(), 'error' => $error));
}

This is my Form Class:

<?php

namespace Trade\TradeBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;


class UserType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
    $builder->add('username', 'text', array('required' => false));
    $builder->add('password', 'password', array('required' => false));
}

public function getName()
{
    return 'user';
}

public function getDefaultOptions(array $options)
{
    return array(
        'data_class' => 'Trade\TradeBundle\Entity\User'
    );
}
}

This is my Form:

{% if error %}
    <div class="alert alert-error">{{ error }}</div>
{% endif %}
<form action="{{ path('account_signin_check') }}" method="post" class="form-inline" novalidate>
    <table class="table">
        <tr>
            <td style="width: 120px;">{{ form_label(form.username) }} <span class="required">*</span></td>
            <td style="width: 220px;">{{ form_widget(form.username, { 'attr': {'placeholder': 'Username'} }) }}</td>
            <td class="form-error" id="email_error">{{ form_errors(form.username) }}</td>
        </tr>
        <tr>
            <td>{{ form_label(form.password) }} <span class="required">*</span></td>
            <td>{{ form_widget(form.password, { 'attr': {'placeholder': 'Password'} }) }}</td>
            <td class="form-error" id="password_error">{{ form_errors(form.password) }}</td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: right;">
                {{ form_rest(form) }}
                <input type="reset" value="Cancel" class="btn" />
                <input type="submit" value="Sign in" class="btn btn-danger" />
            </td>
        <td>&nbsp;</td>
        </tr>
    </table>
</form>

When I try to login, BadCredentialsException is shown. I don’t know why. I think I did everything right according to Symfony’s documentation Please, help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:25:57+00:00Added an answer on June 1, 2026 at 6:25 pm

    Try with the input names like this _username and _password or in your security.yml try to put this under secured_area

    username_parameter: username
    password_parameter: password
    

    Maybe it helps you !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code: // my article fixture <?php namespace My\BlogBundle\DataFixtures\ORM; use Doctrine\Common\DataFixtures\AbstractFixture; use
I try to use this mapping : @Entity @Table(name=ecc.\RATE\) @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name=DISCRIMINATOR, discriminatorType= DiscriminatorType.STRING) public
I'm getting this error on my production environnent: (from prod.log) [2012-01-30 17:00:51] request.CRITICAL: Doctrine\ORM\Mapping\MappingException:
I have this file: #src/Jander/JanderBundle/resources/config/doctrine/metadata/orm/ Propuestas.orm.yml Propuestas: type: entity table: propuestas fields: id: id:
I have an Entity class that looks like this: <?php namespace Entities; /** @Entity
I'm getting this error when I try to clear the cache (for example): [Doctrine\ORM\Mapping
I have entity Product and entity Subcategory : Subcategory.php namespace Project\Entities; /** * Subcategory
I'm new to PHP and also with Doctrine. (Worked before with Hibernate ORM implementation).
mI've this entity class: @Entity public class User implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO) private
If I have this entity: @Entity class Pet { @Id long id; public enum

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.