如何解决方法检查登录名和密码
| 此方法应将用户提供的登录名/密码与数据库中存储的登录名/密码进行比较,但是此方法始终返回false,指令braek不起作用!public String loginPasswordCheck() {
Connectionx cx = new Connectionx();
Connection con = (Connection) cx.Connxion(\"com.MysqL.jdbc.Driver\",\"jdbc:MysqL://localhost/kpidb\",\"root\",\"root\");
String log;
String pwd;
String checkaccess = \"success\";
int profil_user;
HashMap<String,String> mapLoginPWD = new HashMap<String,String>();
HashMap<String,HashMap<String,String>> mapID_LoginPWD = new HashMap<String,String>>();
HashMap<String,String> temp = new HashMap<String,String>();
String sqlLogin;
sqlLogin = \"select PROFIL_USER_ID,login,password from profil_user;\";
try {
st = (PreparedStatement) con.prepareStatement(sqlLogin);
ResultSet rs1 = st.executeQuery();
while (rs1.next()) {
profil_user = rs1.getInt(\"PROFIL_USER_ID\");
profil_user_id = String.valueOf(profil_user);
log = rs1.getString(\"login\");
pwd = rs1.getString(\"password\");
mapLoginPWD.put(log,pwd);
mapID_LoginPWD.put(profil_user_id,mapLoginPWD);
Iterator iteratorkeymaploginPWD = mapID_LoginPWD.keySet().iterator();
while (iteratorkeymaploginPWD.hasNext()) {
String myKeylog = (String) iteratorkeymaploginPWD.next();
temp = mapID_LoginPWD.get(myKeylog);
Iterator iteratortemp = temp.keySet().iterator();
while (iteratortemp.hasNext()) {
String keyTemplog = (String) iteratortemp.next();
String valueTemppwd = temp.get(keyTemplog);
temp.clear();
mapID_LoginPWD.clear();
boolean bool = true;
if (!(this.login.equalsIgnoreCase(keyTemplog)) && !(this.password.equalsIgnoreCase(valueTemppwd)) && (bool)) {
bool = false;
checkaccess = \"fail\";
} else {
checkaccess = \"success\";
break;
}
}
}
}
}
catch (sqlException e) {
e.printstacktrace();
}
return checkaccess;
}
解决方法
逻辑很难遵循,但我相信
boolean bool = true;
需要先来
while (iteratortemp.hasNext()) {
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。