0

I am using criteria to check if username and password from json are correct. I am sure that input username and password are in correct case but it always returns me object even if the letter case are different.

public Admin getLoggedAdminInformation(String username, String password){

   Criteria criteria = criteria()
            .add(Restrictions.eq("userName", username))
            .add(Restrictions.eq("password", password));

   return (Admin) criteria.uniqueResult();
}
  • 3
    have you tested your query directly in your database SQL console ? (what database it is, and what is the SQL column type by the way ?) It could be that your database is case insensitive when comparing. – Thierry May 02 '17 at 06:56

1 Answers1

1

Restrictions.eq just return a SimpleExpression object with ignoreCase is false. So it will create the SQL with the exact same value that you provided.

public static SimpleExpression eq(String propertyName, Object value) {
        return new SimpleExpression(propertyName, value, "=");
    }

So this case insensitive comparison is a behavior of the database. it depends on the database server or table or column configuration.

Ex: in MS SQL server, this is based on the collation of the database, can be overrrieden in table level or column level. sample collation name is Latin1_General_CI_AS , here CI = Case insensitive,AS = accent sensitive.

hunter
  • 3,963
  • 1
  • 16
  • 19