/* administrators IsPass * 管理员账号登录判断,判断是否可以登录 * 输入参数为:管理员账号,即id(String);密码,即pass(String) * 若有此账号信息且密码核对成功,即登录成功,则返回true,若此账号未有记录或密码核对失败或已被删除,即登录失败,则返回false * */ public boolean root_IsPass(String id,String pass) throws Exception { String pas = root_GetPassword(id); if(pas!=null) { if(!pas.equals("")) { if (pass != null) { if (BCrypt.checkpw(pass,pas)) return true; else return false; } else return false; } else return false; } else return false; } public String root_GetPassword(String id) throws Exception { String sql="select * from administrators where id = ?"; PreparedStatement pre = connect.prepareStatement(sql); pre.setString(1,id); ResultSet rs = pre.executeQuery(); String password = null; while(rs.next()) { password=rs.getString(2); } pre.close(); if(password!=null) return password; else return null; } public void root_add(int id,String password) throws Exception { String sql = "insert into administrators(id,password) values(?,?);"; PreparedStatement pre = connect.prepareStatement(sql); pre.setInt(1,id); pre.setString(2,BCrypt.hashpw(password,BCrypt.gensalt())); int count=pre.executeUpdate(); pre.close(); }
标签:总结,pre,return,String,每日,23.3,false,password,id From: https://www.cnblogs.com/laobing6214/p/17284433.html