title: Symfony: Load Security Users from the Database
body: <p>I read the official documentation of Symfony in order to give access to a specific page. I followed the instructions, but when I insert user and pw the I am not redirected to protected page.</p>
  
  <p>This is the entity</p>
  
  <pre><code>namespace AppBundle\Entity;
  use Symfony\Component\Security\Core\User\UserInterface;
  use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
  * @ORM\Entity
  * @ORM\Table(name="users")
  */
  class User implements UserInterface, \Serializable
  {
  /**
   * @ORM\Column(type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @ORM\Column(type="string", length=25, unique=true)
   */
  private $username;
  
  /**
   * @ORM\Column(type="string", length=64)
   */
  private $password;
  
  /**
   * @ORM\Column(type="string", length=60, unique=true)
   */
  private $email;
  
  /**
   * @ORM\Column(name="is_active", type="boolean")
   */
  private $isActive;
  
  public function __construct()
  {
      $this-&gt;isActive = true;
      // may not be needed, see section on salt below
      // $this-&gt;salt = md5(uniqid(null, true));
  }
  
  public function getUsername()
  {
      return $this-&gt;username;
  }
  
  public function getSalt()
  {
      // you *may* need a real salt depending on your encoder
      // see section on salt below
      return null;
  }
  
  public function getPassword()
  {
      return $this-&gt;password;
  }
  
  public function getRoles()
  {
      return array('ROLE_ADMIN');
  }
  
  public function eraseCredentials()
  {
  }
  
  /** @see \Serializable::serialize() */
  public function serialize()
  {
      return serialize(array(
          $this-&gt;id,
          $this-&gt;username,
          $this-&gt;password,
          // see section on salt below
          // $this-&gt;salt,
      ));
  }
  
  /** @see \Serializable::unserialize() */
  public function unserialize($serialized)
  {
      list (
          $this-&gt;id,
          $this-&gt;username,
          $this-&gt;password,
          // see section on salt below
          // $this-&gt;salt
      ) = unserialize($serialized);
     }
  </code></pre>
  
  <p>This is the security.yml</p>
  
  <pre><code>security:
  encoders:
      AppBundle\Entity\User:
          algorithm: bcrypt
  
  
  role_hierarchy:
      ROLE_ADMIN:       ROLE_ADMIN
      ROLE_SUPER_ADMIN: [ ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
  
  providers:
      our_db_provider:
          entity:
              class: AppBundle:User
              property: username
  
  firewalls:
      dev:
          pattern: ^/(_(profiler|wdt|error)|css|images|js)/
          security: false
  
      main:
          anonymous: ~
          http_basic: ~
  
      default:
         pattern:    ^/
         http_basic: ~
         provider: our_db_provider
  
  access_control:
      - { path: ^/dashboard/admin, roles: ROLE_ADMIN }
  </code></pre>
  
  <p>The password has been inserted manually in the database using this BCrypt <a href="https://www.dailycred.com/article/bcrypt-calculator" rel="nofollow">tool</a></p>
  
  <p>What I am doing wrong?</p>