Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean UserSignup(String userName, String password, String secQuestion, String secAnswer, int status_id, String position){
- if(userName.isEmpty() || userName == null || password.isEmpty() || password == null || secQuestion.isEmpty() || secQuestion == null || secAnswer.isEmpty() || secAnswer == null || position.isEmpty() || position == null)
- {
- }
- else{
- Connection conn = null;
- Statement stmt = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException ex) {
- ex.printStackTrace();
- }
- try {
- conn = DriverManager.getConnection(url, user, pass);
- conn.setAutoCommit(false);
- PreparedStatement ps;
- String sqlInsert = "insert into User(user_name, password, security_q, security_a, status_id, position) values(?,?,?,?,?,?)";
- ps = conn.prepareStatement(sqlInsert);
- ps.setString(1, userName);
- ps.setString(2, BCrypt.hashpw(password, BCrypt.gensalt(10)));
- ps.setString(3, BCrypt.hashpw(secQuestion, BCrypt.gensalt(10)));
- ps.setString(4, BCrypt.hashpw(secAnswer, BCrypt.gensalt(10)));
- ps.setInt(5, status_id);
- ps.setString(6, position);
- ps.executeUpdate();
- conn.commit();
- return true;
- } catch(Exception ex) {
- ex.printStackTrace();
- } finally {
- try {
- if (stmt != null) stmt.close();
- if (conn != null) conn.close();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- }
- return false;
- }
- public String UserCheck(String userName){
- Connection conn = null;
- PreparedStatement ps = null;
- String check = "";
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch(ClassNotFoundException e) {
- e.printStackTrace();
- }
- try {
- conn = DriverManager.getConnection(url, user, pass);
- conn.setAutoCommit(false);
- String sqlInsert = "select user_id, user_name from User where user_name = ?";
- ps = conn.prepareStatement(sqlInsert);
- ps.setString(1, userName);
- ResultSet rset = ps.executeQuery();
- if(rset.next()) {
- check = rset.getString("user_name");
- int rid = rset.getInt("user_id");
- Bean_User row = new Bean_User();
- row.setUserID(rid);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- try {
- if (ps != null) ps.close();
- if (conn != null) conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return check;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement