用户注册后,他通常会尝试登录,但他通常不能用拳头尝试,有时需要一些时间才能成功登录。所以,最重要的是:
SessionFactory factory = HibernateUtil.getSessionFactory();
Session hSession = factory.openSession();
Transaction tx = null;
List<UserTable> list1 = null;
try {
tx = hSession.beginTransaction();
Criteria crit = hSession.createCriteria(UserTable.class).add(
Restrictions.like("email", email));
list1 = crit.list();
tx.commit();
} catch (Exception e) {
e.printStackTrace();
if (tx != null)
tx.rollback();
} finally {
hSession.close();
}
// the 'if' is usualy 'true' after some time...
if(list1.size() > 0) {
String hash = null;
try {
hash = EncryptPassword.encryptPassword(password);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
if (list1.get(0).getPassword().equals(hash)) {
session.put("email", email);
log.info("login successful: " + email);
return SUCCESS;
} else {
log.info(email + " - the deer does't remember password");
}
}
addActionError(getText("error.login"));
// the next warning usually happens twice or more
log.warn("login error: " + email);
return ERROR;
这是什么?一个长期运行的交易或其他什么?