I have to do in Spring Boot an LoginController which verifies if a username and password exists in database or not. For verification I made my repository, UserRepository which extends CrudRepository.
When I send the username and password to repository, they are sent okay, but when I do the query it doesn't take into account the case sensitivity of my parameters.
For example: in USER table I have username = "Test" and password = "test" If I make an request with username = "test" and password = "Test" it seems like I have this username and password in the table, but I haven't.
Bellow I put a peace of code with my query and I would be very grateful if you could help me with this problem.
Thank you for your time.
@Repository
public interface UserRepository extends CrudRepository<User, Long>{
User findByUsername(String username);
User findByEmail(String email);
@Query(value = "SELECT user_id FROM user WHERE username = :username AND password = :password", nativeQuery = true)
Long findUserIdByUsernameAndPassword(@Param("username") String username, @Param("password") String password);
}
IgnoreCase
is a special keyword for Spring Data JPA queries.findByEmail
should be case-sensitive, butfindByEmailIgnoreCase
would not be case-sensitive. What have you tried to check the values being passed into the function and the values on the DB are not the same casing?