login

public void validate() {
// TODO Auto-generated method stub
if ("".equals(userName)) {
addFieldError("userName", "用户名不能为空");
} else if ("".equals(passWord)) {
addFieldError("passWord", "密码不能为空");
} else {
int flag = userInfoIDao.validate(userName, passWord);
if (flag == UserInfoDaoImpl.NAMEISERROR) {
addFieldError("username", "此用户名不存在");
} else if (flag == UserInfoDaoImpl.PWDISERROR) {
addFieldError("password", "密码错误");
}
}
}

public final static int NAMEISERROR = 1;
public final static int PWDISERROR = 2;
public final static int INFOISRIGHT = 3;


public int validate(String username, String password) {
System.out.println(username + ";" + password);
String sql = "from UserInfo where userName=?";
Query query = session.createQuery(sql);
query.setString(0, username);
List<UserInfo> list = query.list();
if (list.size() == 0) {
return NAMEISERROR;
} else {
sql = "from UserInfo where userName=? and userPwd=?";
query = session.createQuery(sql);
query.setString(0, username);
query.setString(1, password);
list = query.list();
if (list.size() == 0) {
return PWDISERROR;
}
}
return INFOISRIGHT;
}

你可能感兴趣的:(sql)