Are the criteria in sleep mode insensitive?

I use api criteria for validation. If the username exists or not. After that, I verify the password. But the username is not case sensitive. I want to make it case sensitive.

Criteria criteria2 = session.createCriteria(UserMaster.class); criteria2.add(Restrictions.eq("userName", userName)); userDetails = (UserMaster)criteria2.uniqueResult(); if(userDetails != null) { //logic goes here } 

Any help would be appreciated.

+6
source share
3 answers

I did with native sql as follows

 Query query = session.createSQLQuery("select * from USER_MASTER where binary USER_NAME='"+userName+"'").addEntity(UserMaster.class); userDetails = (UserMaster)query.uniqueResult(); if(userDetails != null) { //code goes here } 
0
source

Comparison of strings depends on the brand and version of the database and database settings. Some databases, such as Microsoft SQL Server, by default compare strings differently, while others compare strings case-sensitive.

Check your database settings; Find your brand documentation and database version to find out how to change this setting.

If it is really MS SQL Server, then look at an example on this question: Will Sql Server check the sensitivity of checks?

+3
source

I can say a simple solution. But this is not a direct path. Encrypt your username using MD5 and save it in the database. When comparing a username, you must encrypt this MD5 username and compare it with the username stored in the database. But I do not recommend this solution, anyway, you can also use this. :)

0
source

Source: https://habr.com/ru/post/987492/


All Articles