title: Spring Security bcrypt encoding login is not working
body: <p>My application is in hibernate and spring MVC. Previously log in used to work but now I implemented bcrypt encoding for password. after that nothing is working. I changed almost everything. Here I am giving you my code and config files. Please help me in finding out the problem.</p>
  
  <p>app-security.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:security="http://www.springframework.org/schema/security"
         xmlns:p="http://www.springframework.org/schema/p" 
         xsi:schemaLocation="http://www.springframework.org/schema/beans
                             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                             http://www.springframework.org/schema/context
                             http://www.springframework.org/schema/context/spring-context-3.0.xsd
                             http://www.springframework.org/schema/security
                             http://www.springframework.org/schema/security/spring-security-3.2.xsd"&gt;
  
      &lt;security:global-method-security secured-annotations="enabled" /&gt;
  
      &lt;!-- These beans handle successful login and failure cases of login --&gt;
      &lt;bean id="myAuthenticationSuccessHandler" class="com.app.security.handler.MySimpleUrlAuthenticationSuccessHandler" /&gt;
      &lt;bean id="myAuthenticationFailureHandler" class="com.app.security.handler.MySimpleUrlAuthenticationFailureHandler" /&gt;
  
      &lt;!-- Encrypter to encrypt password --&gt;
      &lt;bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/&gt;
  
      &lt;security:http auto-config="true"&gt;&lt;!-- 
          &lt;security:intercept-url pattern="/home*"    access="ROLE_USER" /&gt; --&gt;
          &lt;security:intercept-url pattern="/admin"    access="ROLE_ADMIN" /&gt;
          &lt;security:intercept-url pattern="/user"     access="ROLE_USER" /&gt;
          &lt;security:intercept-url pattern="/group-admin"  access="ROLE_GROUP_ADMIN" /&gt;
          &lt;security:intercept-url pattern="/sponsor"  access="ROLE_SPONSOR" /&gt;
  
          &lt;security:form-login    login-page="/login" 
                                  default-target-url="/home"
                                  authentication-failure-handler-ref="myAuthenticationFailureHandler" 
                                  authentication-success-handler-ref="myAuthenticationSuccessHandler"
          /&gt;
          &lt;security:logout logout-success-url="/logout" /&gt;
      &lt;/security:http&gt;
  
      &lt;security:authentication-manager&gt;
        &lt;security:authentication-provider&gt;
          &lt;security:password-encoder ref="encoder" /&gt;
          &lt;security:jdbc-user-service data-source-ref="dataSource"  
              users-by-username-query="select user_id as userId, username, password, email_address as emailAddress, active from users where username=?" 
              authorities-by-username-query="select us.user_id as userId, us.username as username, us.email_address as emailAddress, us.active as active, ur.roles from users us, user_roles ur 
                where us.role_id = ur.role_id and us.username =?  " 
          /&gt;
        &lt;/security:authentication-provider&gt;
      &lt;/security:authentication-manager&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>UserService.java</p>
  
  <pre><code>@Service
  public class UserService {
  
      @Autowired
      private UserDaoImpl userDaoImpl;
      @Autowired
      BCryptPasswordEncoder passwordEncoder;
      /**
       * Save data in USER table
       * @param user
       */
      public void insert(User user) {
          //Encrypting password
          user.setPassword(passwordEncoder.encode(user.getPassword()));
  
          userDaoImpl.save(user);
      }
  </code></pre>
  
  <p>User.java</p>
  
  <pre><code>@Entity
  @Table(name="USERS")
  public class User implements Serializable {
  
      private static final long serialVersionUID = 2158419746939747203L;
  
      @Id
      @Column(name="USER_ID")
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private long userId;
  
      @Column(name="USERNAME", unique = true, length=45, nullable=false)
      @NotEmpty @NotNull @Size(min=6, max=20)
      @UniqueCheck(classname="User", fieldname="username")
      private String username;
  
      @Column(name="PASSWORD", length=100, nullable=false)
      @NotEmpty @NotNull @Size(min=6, max=100)
      private String password;
  
      @Column(name="EMAIL_ADDRESS", unique = true, length=100, nullable=false)
      @UniqueCheck(classname="User", fieldname="emailAddress")
      @NotEmpty
      private String emailAddress;
  
      @Column(name="ACTIVE", nullable=false )
      private Integer active;
  
      @Column(name="ROLE_ID", nullable=false)
      private String roleid;
  //getter setters
  </code></pre>
  
  <p>Let me know if any other info is needed</p>