1、注入sql语句使其先行检测是否事先存在已有账户
String sql = "select id from user_info where user_name = ?"; if(new DBLink().exist(sql, userName)) { System.out.println("用户名已存在,操作终止"); return; }2、检测密码和重复密码是否一致
if(!Password.equals(rePassword)) { System.out.println("两次输入密码不一致,操作终止"); return; }3、随机生成id添加入数据库
String id = UUID.randomUUID().toString();4、利用MD5Tool加密密码
Password = MD5Tool.encrypt(Password);5、利用sql语句将数据添加进数据库
sql = "insert into user_info (id,user_name,password) values('"+id+"',?,?)"; if(new DBLink().update(sql, userName,Password)) { System.out.println("注册成功"); return; }1、登录之前再次将密码进行加密,加密相同的内容得到的密文相同 password = MD5Tool.encrypt(password); 2、注入sql语句使其先行检测
String sql = "select id from user_info where user_name = ? and password = ?"; if(new DBLink().exist(sql, userName,password)) { System.out.println("登录成功"); return; }