Bad credentials Exception | Spring Security <p>Trying to use Spring security for authentication process, but getting <code>Bad credentials</code> exception.here is how I have defined things in my <code>spring-security.xml</code> file</p> <pre><code>&lt;beans:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"&gt; &lt;/beans:bean&gt; &lt;beans:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"&gt; &lt;/beans:bean&gt; &lt;authentication-manager id="customerAuthenticationManager"&gt; &lt;authentication-provider user-service-ref="customerDetailsService"&gt; &lt;password-encoder hash="sha" /&gt; &lt;/authentication-provider&gt; &lt;/authentication-manager&gt; </code></pre> <p><code>customerDetailsService</code> is our own implementation being provided to spring security.In my Java code while registering user, I am encoding provided password before adding password to Database something like</p> <pre><code>import org.springframework.security.authentication.encoding.PasswordEncoder; @Autowired private PasswordEncoder passwordEncoder; customerModel.setPassword(passwordEncoder.encodePassword(customer.getPwd(), null)); </code></pre> <p>When I tried to debug my application, it seems Spring is calling <code>AbstractUserDetailsAuthenticationProvider</code> authenticate method and when its performing additionalAuthenticationCheck with <code>additionalAuthenticationChecks(user, (UsernamePasswordAuthenticationToken) authentication);</code> of <code>DaoAuthenticationProvider</code>, it throwing Bad credential exception at following point</p> <pre><code>if (authentication.getCredentials() == null) { logger.debug("Authentication failed: no credentials provided"); throw new BadCredentialsException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), userDetails); } </code></pre> <p>I am not sure where I am doing wrong and what needs to be done here to put things in right place, I already checked customer is there in database and password is encoded.</p>