Guest User

Untitled

a guest
Jan 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. public void doPost(HttpServletRequest req, HttpServletResponse resp)
  2. throws
  3. IOException {
  4. resp.setContentType("text/html");
  5. PrintWriter out = resp.getWriter();
  6.  
  7. String email = req.getParameter("email");
  8. String userName = req.getParameter("username");
  9. String pass = req.getParameter("password");
  10.  
  11. if(!email.isEmpty() && !userName.isEmpty() && !pass.isEmpty()){
  12. out.println("Welcome n" + userName + "t" +email + "t" +pass);
  13. String publicKey = "";
  14. String privateKey = "";
  15. try {
  16. publicKey = generateKeys.generatePublic();
  17. privateKey = generateKeys.generatePrivate();
  18. } catch (NoSuchAlgorithmException e) {
  19. e.printStackTrace();
  20. }
  21.  
  22. mySql.sqlInsert(userName, pass, publicKey, privateKey);
  23. boolean ans =mySql.validUser(userName);
  24.  
  25. out.print(ans);
  26. }
  27. else{
  28. out.println("Please fill in all the Fields");
  29. }
  30.  
  31. public static void sqlInsert(String name, String pass, String publicKey,
  32. String privateKey) {
  33. // String msg;
  34. String sql;
  35. try {
  36. sql = "INSERT INTO users (uName,password, publicKey,privateKey) VALUES(?,?,?,?)";
  37. Class.forName("com.mysql.jdbc.Driver");
  38. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/c_schema?autoReconnect=true&useSSL=false", "root", "");
  39. PreparedStatement stm = con.prepareStatement(sql);
  40. stm.setString(1, name);
  41. stm.setString(2, pass);
  42. stm.setString(3, publicKey);
  43. stm.setString(4, privateKey);
  44. stm.executeUpdate();
  45.  
  46. } catch (ClassNotFoundException e) {
  47. e.printStackTrace();
  48. } catch (SQLException e) {
  49. e.printStackTrace();
  50. }
  51. }
Add Comment
Please, Sign In to add comment