Advertisement
Guest User

Untitled

a guest
May 9th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. public boolean UserSignup(String userName, String password, String secQuestion, String secAnswer, int status_id, String position){
  2.  
  3.  
  4. if(userName.isEmpty() || userName == null || password.isEmpty() || password == null || secQuestion.isEmpty() || secQuestion == null || secAnswer.isEmpty() || secAnswer == null || position.isEmpty() || position == null)
  5. {
  6.  
  7. }
  8. else{
  9.  
  10. Connection conn = null;
  11. Statement stmt = null;
  12.  
  13. try {
  14. Class.forName("com.mysql.jdbc.Driver");
  15. } catch (ClassNotFoundException ex) {
  16. ex.printStackTrace();
  17. }
  18.  
  19. try {
  20.  
  21. conn = DriverManager.getConnection(url, user, pass);
  22. conn.setAutoCommit(false);
  23.  
  24. PreparedStatement ps;
  25.  
  26. String sqlInsert = "insert into User(user_name, password, security_q, security_a, status_id, position) values(?,?,?,?,?,?)";
  27. ps = conn.prepareStatement(sqlInsert);
  28.  
  29. ps.setString(1, userName);
  30. ps.setString(2, BCrypt.hashpw(password, BCrypt.gensalt(10)));
  31. ps.setString(3, BCrypt.hashpw(secQuestion, BCrypt.gensalt(10)));
  32. ps.setString(4, BCrypt.hashpw(secAnswer, BCrypt.gensalt(10)));
  33. ps.setInt(5, status_id);
  34. ps.setString(6, position);
  35.  
  36. ps.executeUpdate();
  37. conn.commit();
  38. return true;
  39.  
  40. } catch(Exception ex) {
  41. ex.printStackTrace();
  42.  
  43. } finally {
  44. try {
  45. if (stmt != null) stmt.close();
  46. if (conn != null) conn.close();
  47. } catch (SQLException ex) {
  48. ex.printStackTrace();
  49. }
  50. }
  51. }
  52.  
  53. return false;
  54. }
  55.  
  56. public String UserCheck(String userName){
  57.  
  58. Connection conn = null;
  59. PreparedStatement ps = null;
  60. String check = "";
  61.  
  62. try {
  63. Class.forName("com.mysql.jdbc.Driver");
  64. } catch(ClassNotFoundException e) {
  65. e.printStackTrace();
  66. }
  67.  
  68. try {
  69. conn = DriverManager.getConnection(url, user, pass);
  70. conn.setAutoCommit(false);
  71.  
  72.  
  73. String sqlInsert = "select user_id, user_name from User where user_name = ?";
  74. ps = conn.prepareStatement(sqlInsert);
  75. ps.setString(1, userName);
  76. ResultSet rset = ps.executeQuery();
  77.  
  78. if(rset.next()) {
  79. check = rset.getString("user_name");
  80. int rid = rset.getInt("user_id");
  81. Bean_User row = new Bean_User();
  82. row.setUserID(rid);
  83. }
  84.  
  85. } catch (SQLException e) {
  86. e.printStackTrace();
  87. } finally {
  88. try {
  89. if (ps != null) ps.close();
  90. if (conn != null) conn.close();
  91. } catch (SQLException e) {
  92. e.printStackTrace();
  93. }
  94. }
  95.  
  96. return check;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement