Esempio n. 1
0
  /**
   * inserts new user
   *
   * @param user user object
   */
  public static void insertUser(User user) {

    Connection con = null;
    try {
      con = DBUtils.getConn();
      String salt = EncryptionUtil.generateSalt();
      PreparedStatement stmt =
          con.prepareStatement(
              "insert into users (first_nm, last_nm, email, username, user_type, password, salt) values (?,?,?,?,?,?,?)");
      stmt.setString(1, user.getFirstNm());
      stmt.setString(2, user.getLastNm());
      stmt.setString(3, user.getEmail());
      stmt.setString(4, user.getUsername());
      stmt.setString(5, user.getUserType());
      stmt.setString(6, EncryptionUtil.hash(user.getPassword() + salt));
      stmt.setString(7, salt);
      stmt.execute();
      DBUtils.closeStmt(stmt);

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      DBUtils.closeConn(con);
    }
  }
Esempio n. 2
0
 /**
  * updates existing user
  *
  * @param user user object
  */
 public static void updateUserNoCredentials(User user) {
   Connection con = null;
   try {
     con = DBUtils.getConn();
     PreparedStatement stmt =
         con.prepareStatement(
             "update users set first_nm=?, last_nm=?, email=?, username=?, user_type=? where id=?");
     stmt.setString(1, user.getFirstNm());
     stmt.setString(2, user.getLastNm());
     stmt.setString(3, user.getEmail());
     stmt.setString(4, user.getUsername());
     stmt.setString(5, user.getUserType());
     stmt.setLong(6, user.getId());
     stmt.execute();
     DBUtils.closeStmt(stmt);
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     DBUtils.closeConn(con);
   }
 }