I have been through this. From that I infer, findBy queries are Case Sensitive and you can add IgnoreCase
for the case insensitive behavior.
I have created a login controller where I am checking if the user credentials are correct or not using findBy query.
myUserDao.findByLoginIdAndPassword(loginId, password);
I am testing this using a Rest Client.
The user present in the DB has loginId as testuser
and a encrypted password a12f4ae0cd227501191616c77ac0a234
.
Now when I enter the user as Testuser
and password as a12f4ae0cd227501191616c77ac0a234
the user is still able to login. The find by query returns successfully with a MyUser Entity even though the username entered has a different case.
=================
EDIT 1: Code for Login
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public ResponseEntity<String> loginUser(@RequestBody Map<String, String> rawpayload) {
String loginId = null;
String password = null;
try {
loginId = rawpayload.get("loginId");
password = rawpayload.get("password");
} catch (Exception e) {
logger.error("",e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Please check your payload format.");
}
MyUser myUser = myUserDao.findByLoginIdAndPassword(loginId, password);
if (myUser == null) {
logger.error("Invalid login ID(" + loginId + ") and password.");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
.body(CommonUtils.createErrorResponseMessage("Invalid loginId or password."));
}
}
logger.info("User '" + loginId + "' logged in successfully.");
return jsonUtils.getJsonForResponse(myUser);
}