Пример #1
0
  public static void adduser(
      int checkid, String player, String email, String password, String ipAddress)
      throws SQLException {
    if (checkid == 1) {
      long timestamp = System.currentTimeMillis() / 1000;
      //
      PreparedStatement ps;
      //
      String salt = Encryption.hash(12, "none", 33, 126);
      String hash = hash("create", player, password, salt);

      ps =
          MySQL.mysql.prepareStatement(
              "INSERT INTO `"
                  + Config.script_tableprefix
                  + "users"
                  + "` (`group_id`, `username`, `password`, `salt`, `email`, `registered`, `registration_ip`, `last_visit`)  VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
              1);
      ps.setInt(1, 3); // group_id
      ps.setString(2, player); // username
      ps.setString(3, hash); // password
      ps.setString(4, salt); // salt
      ps.setString(5, email); // email
      ps.setLong(6, timestamp); // registered
      ps.setString(7, ipAddress); // registration_ip
      ps.setLong(8, timestamp); // last_visit
      //
      Util.logging.mySQL(ps.toString());
      ps.executeUpdate();
      ps.close();

      /*
      ps = MySQL.mysql.prepareStatement("UPDATE `" + Config.script_tableprefix + "config" + "` SET `config_value` = '" + userid + "' WHERE `config_name` = 'newest_user_id'");
      ps.executeUpdate();
      ps = MySQL.mysql.prepareStatement("UPDATE `" + Config.script_tableprefix + "config" + "` SET `config_value` = '" + player + "' WHERE `config_name` = 'newest_username'");
      ps.executeUpdate();
      ps = MySQL.mysql.prepareStatement("UPDATE `" + Config.script_tableprefix + "config" + "` SET `config_value` = config_value + 1 WHERE `config_name` = 'num_users'");
      ps.executeUpdate();
      */
    }
  }
Пример #2
0
 public static String passwordHash(String password, String salt)
     throws NoSuchAlgorithmException, UnsupportedEncodingException {
   return Encryption.SHA1(salt + Encryption.SHA1(password));
 }