@Override public User findByCode(String code) { try { TypedQuery<User> query = em.createQuery("SELECT u FROM User u WHERE u.code = :code", User.class); query.setParameter("code", code); return query.getSingleResult(); } catch (NoResultException e) { LOGGER.log(Level.WARNING, e.toString(), e); return null; } catch (NonUniqueResultException e) { throw new AppException( ErrorInfo.UNIQUE_CONSTRAINT_ERROR, "Has more than one records existing with code =" + code, e); } }
@Override public User findByUsernameAndPassword(String username, String password) { try { TypedQuery<User> query = em.createQuery( "SELECT u FROM User u WHERE u.username = :username and u.password = :password", User.class); query.setParameter("username", username); query.setParameter("password", StringUtil.digest("SHA-256", password)); return query.getSingleResult(); } catch (NoResultException e) { LOGGER.log(Level.WARNING, e.toString(), e); return null; } catch (NonUniqueResultException e) { throw new AppException( ErrorInfo.UNIQUE_CONSTRAINT_ERROR, "Has more than one records existing with username ="******", password = " + password, e); } }