Exemplo n.º 1
0
 /**
  * Change player password
  * 
  * @param Player $player
  * @param string $new_password
  * 
  * @return int|boolean true on SUCCESS or false if the player is not registered, otherwise the current error
  */
 public function changePlayerPassword(Player $player, $new_password)
 {
     $cfg = $this->getConfig()->getAll();
     if ($this->isPlayerRegistered($player->getName())) {
         if (strlen($new_password) < $cfg["minPasswordLength"]) {
             return ServerAuth::ERR_PASSWORD_TOO_SHORT;
         } elseif (strlen($new_password) > $cfg["maxPasswordLength"]) {
             return ServerAuth::ERR_PASSWORD_TOO_LONG;
         } else {
             $this->getServer()->getPluginManager()->callEvent($event = new Events\ServerAuthPasswordChangeEvent($player, $new_password));
             if ($event->isCancelled()) {
                 return ServerAuth::CANCELLED;
             }
             if ($this->getDataProvider()) {
                 //Check MySQL connection
                 if ($this->getDatabase() && $this->getDatabase()->ping()) {
                     $query = "UPDATE " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata SET password='******' WHERE user='******'";
                     if ($this->getDatabase()->query($query)) {
                         return ServerAuth::SUCCESS;
                     } else {
                         return ServerAuth::ERR_GENERIC;
                     }
                 } else {
                     return ServerAuth::ERR_GENERIC;
                 }
             } else {
                 $data = new Config($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml"), Config::YAML);
                 $data->set("password", hash($this->getPasswordHash(), $new_password));
                 $data->save();
                 return ServerAuth::SUCCESS;
             }
         }
     } else {
         return $this->isPlayerRegistered($player->getName());
     }
 }
Exemplo n.º 2
0
 /**
  * Change player password
  * 
  * @param Player|OfflinePlayer $player
  * @param string $new_password
  * 
  * @return int|boolean true on SUCCESS or false if the player is not registered, otherwise the current error
  */
 public function changePlayerPassword($player, $new_password)
 {
     if ($player instanceof Player || $player instanceof OfflinePlayer) {
         $cfg = $this->getConfig()->getAll();
         if ($this->isPlayerRegistered($player->getName())) {
             if (strlen($new_password) < $cfg["minPasswordLength"]) {
                 return ServerAuth::ERR_PASSWORD_TOO_SHORT;
             } elseif (strlen($new_password) > $cfg["maxPasswordLength"]) {
                 return ServerAuth::ERR_PASSWORD_TOO_LONG;
             } else {
                 //Reset cancelled message
                 $this->canc_message = $this->chlang["operation-cancelled"];
                 $this->getServer()->getPluginManager()->callEvent($event = new Events\ServerAuthPasswordChangeEvent($player, $new_password));
                 if ($event->isCancelled()) {
                     return ServerAuth::CANCELLED;
                 }
                 if ($this->getDataProvider()) {
                     //Check MySQL connection
                     if ($this->getDatabase() && $this->getDatabase()->ping()) {
                         $stmt = $this->getDatabase()->prepare("UPDATE " . $this->getDatabaseConfig()["table_prefix"] . "serverauthdata SET password=? WHERE user=?");
                         $stmt_password = hash($this->getPasswordHash(), $new_password);
                         $stmt_player = strtolower($player->getName());
                         $stmt->bind_param("ss", $stmt_password, $stmt_player);
                         if ($stmt->execute()) {
                             $stmt->close();
                             return ServerAuth::SUCCESS;
                         } else {
                             $stmt->close();
                             return ServerAuth::ERR_GENERIC;
                         }
                     } else {
                         return ServerAuth::ERR_GENERIC;
                     }
                 } else {
                     $data = new Config($this->getDataFolder() . "users/" . strtolower($player->getName() . ".yml"), Config::YAML);
                     $data->set("password", hash($this->getPasswordHash(), $new_password));
                     $data->save();
                     return ServerAuth::SUCCESS;
                 }
             }
         } else {
             return $this->isPlayerRegistered($player->getName());
         }
     } else {
         return ServerAuth::ERR_USER_NOT_REGISTERED;
     }
 }