Jump to content
  • 0

Password Changer Console Error


Question

Posted

Γειά σας. 'Eχω βάλει ένα κώδικα για passwrod changer in game δουλεύει κανονικά αλλά οταν πατάω να αλλάξω το pass δεν γίνεται τίποτα και βγάζει error στο console και λέει could not update account of. Έχω l2jfrozen..

Photo: http://imageshack.us/photo/my-images/515/kyl.png/

Ο κώδικας

/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package com.l2jfrozen.gameserver.model.actor.instance;

import com.l2jfrozen.crypt.Base64;
import com.l2jfrozen.gameserver.ai.CtrlIntention;
import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
import com.l2jfrozen.gameserver.network.serverpackets.LeaveWorld;
import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
import com.l2jfrozen.util.database.L2DatabaseFactory;

import java.security.MessageDigest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;
import javolution.text.TextBuilder;

public class L2PasswordChangerInstance extends L2FolkInstance
{
  public L2PasswordChangerInstance(int objectId, L2NpcTemplate template)
  {
    super(objectId, template);
  }

  public void onBypassFeedback(L2PcInstance player, String command)
  {
    if (command.startsWith("change_password"))
    {
      StringTokenizer st = new StringTokenizer(command);
      st.nextToken();
      String currPass = null;
      String newPass = null;
      String repeatNewPass = null;
      try
      {
        if (st.hasMoreTokens())
        {
          currPass = st.nextToken();
          newPass = st.nextToken();
          repeatNewPass = st.nextToken();
        }
        else
        {
          player.sendMessage("Please fill in all the blanks before requesting for a password change.");
          return;
        }
        changePassword(currPass, newPass, repeatNewPass, player);
      }
      catch (StringIndexOutOfBoundsException e)
      {
      }
    }
  }

  public void onAction(L2PcInstance player)
  {
    if (!canTarget(player)) {
      return;
    }

    if (this != player.getTarget())
    {
      player.setTarget(this);

      player.sendPacket(new MyTargetSelected(getObjectId(), 0));

      player.sendPacket(new ValidateLocation(this));
    }
    else if (!canInteract(player))
    {
      player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
    }
    else
    {
      showHtmlWindow(player);
    }

    player.sendPacket(new ActionFailed());
  }

  private void showHtmlWindow(L2PcInstance activeChar)
  {
    NpcHtmlMessage nhm = new NpcHtmlMessage(5);
    TextBuilder replyMSG = new TextBuilder("");

    replyMSG.append("<html><title>L2 InStadia Account Manager</title>");
    replyMSG.append("<body><center>");
    replyMSG.append("To change your password:<br1> First fill in your current password and then your new!</font><br>");
    replyMSG.append("Current Password: <edit var=\"cur\" width=100 height=15><br>");
    replyMSG.append("New Password: <edit var=\"new\" width=100 height=15><br>");
    replyMSG.append("Repeat New Password: <edit var=\"repeatnew\" width=100 height=15><br><br>");
    replyMSG.append("<button value=\"Change Password\" action=\"bypass -h npc_" + getObjectId() + "_change_password $cur $new $repeatnew\" width=204 height=20 back=\"sek.cbui75\" fore=\"sek.cbui75\">");
    replyMSG.append("</center></body></html>");

    nhm.setHtml(replyMSG.toString());
    activeChar.sendPacket(nhm);

    activeChar.sendPacket(new ActionFailed());
  }

  public static boolean changePassword(String currPass, String newPass, String repeatNewPass, L2PcInstance activeChar)
  {
    if (newPass.length() < 5)
    {
      activeChar.sendMessage("The new password is too short!");
      return false;
    }
    if (newPass.length() > 20)
    {
      activeChar.sendMessage("The new password is too long!");
      return false;
    }
    if (!newPass.equals(repeatNewPass))
    {
      activeChar.sendMessage("Repeated password doesn't match the new password.");
      return false;
    }

    Connection con = null;
    String password = null;
    try
    {
      MessageDigest md = MessageDigest.getInstance("SHA");
      byte[] raw = currPass.getBytes("UTF-8");
      raw = md.digest(raw);
      String currPassEncoded = Base64.encodeBytes(raw);

      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts WHERE login=?");
      statement.setString(1, activeChar.getAccountName());
      ResultSet rset = statement.executeQuery();
      while (rset.next())
      {
        password = rset.getString("password");
      }
      rset.close();
      statement.close();
      byte[] password2 =
   null;
      if (currPassEncoded.equals(password))
      {
        password2 = newPass.getBytes("UTF-8");
        password2 = md.digest(password2);

        PreparedStatement statement2 = con.prepareStatement("UPDATE accounts SET password=? WHERE login=?");
        statement2.setString(1, Base64.encodeBytes(password2));
        statement2.setString(2, activeChar.getAccountName());
        statement2.executeUpdate();
        statement2.close();

        activeChar.sendMessage("Congratulations! Your password has been changed succesfully. You will now be disconnected for security reasons. Please login again!");
        try
        {
          Thread.sleep(3000L);
        }
        catch (Exception e)
        {
        }

        activeChar.deleteMe();

        activeChar.sendPacket(new LeaveWorld());
      }
      else
      {
        activeChar.sendMessage("The current password you've inserted is incorrect! Please try again!");
       
        return password2 != null;
      }
    }
    catch (Exception e)
    {
      _log.warning("could not update the password of account: " + activeChar.getAccountName());
    }
    finally
    {
      try
      {
        if (con != null)
          con.close();
      }
      catch (SQLException e)
      {
        _log.warning("Failed to close database connection!");
      }

    }

    return true;
  }
}

Recommended Posts

  • 0
Posted

Γειά σας. 'Eχω βάλει ένα κώδικα για passwrod changer in game δουλεύει κανονικά αλλά οταν πατάω να αλλάξω το pass δεν γίνεται τίποτα και βγάζει error στο console και λέει could not update account of. Έχω l2jfrozen..

Δείξε μας μια φωτο με το error που σου βγάζει..
  • 0
Posted

Δείξε μας μια φωτο με το error που σου βγάζει..

Το έκανα update το post και ανέβασα photo . Δες την και πες μου.
  • 0
Posted

Για κάνε paste εδώ τον code του npc.

/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package com.l2jfrozen.gameserver.model.actor.instance;

import com.l2jfrozen.crypt.Base64;
import com.l2jfrozen.gameserver.ai.CtrlIntention;
import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
import com.l2jfrozen.gameserver.network.serverpackets.LeaveWorld;
import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
import com.l2jfrozen.util.database.L2DatabaseFactory;

import java.security.MessageDigest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;
import javolution.text.TextBuilder;

public class L2PasswordChangerInstance extends L2FolkInstance
{
  public L2PasswordChangerInstance(int objectId, L2NpcTemplate template)
  {
    super(objectId, template);
  }

  public void onBypassFeedback(L2PcInstance player, String command)
  {
    if (command.startsWith("change_password"))
    {
      StringTokenizer st = new StringTokenizer(command);
      st.nextToken();
      String currPass = null;
      String newPass = null;
      String repeatNewPass = null;
      try
      {
        if (st.hasMoreTokens())
        {
          currPass = st.nextToken();
          newPass = st.nextToken();
          repeatNewPass = st.nextToken();
        }
        else
        {
          player.sendMessage("Please fill in all the blanks before requesting for a password change.");
          return;
        }
        changePassword(currPass, newPass, repeatNewPass, player);
      }
      catch (StringIndexOutOfBoundsException e)
      {
      }
    }
  }

  public void onAction(L2PcInstance player)
  {
    if (!canTarget(player)) {
      return;
    }

    if (this != player.getTarget())
    {
      player.setTarget(this);

      player.sendPacket(new MyTargetSelected(getObjectId(), 0));

      player.sendPacket(new ValidateLocation(this));
    }
    else if (!canInteract(player))
    {
      player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
    }
    else
    {
      showHtmlWindow(player);
    }

    player.sendPacket(new ActionFailed());
  }

  private void showHtmlWindow(L2PcInstance activeChar)
  {
    NpcHtmlMessage nhm = new NpcHtmlMessage(5);
    TextBuilder replyMSG = new TextBuilder("");

    replyMSG.append("<html><title>L2 InStadia Account Manager</title>");
    replyMSG.append("<body><center>");
    replyMSG.append("To change your password:<br1> First fill in your current password and then your new!</font><br>");
    replyMSG.append("Current Password: <edit var=\"cur\" width=100 height=15><br>");
    replyMSG.append("New Password: <edit var=\"new\" width=100 height=15><br>");
    replyMSG.append("Repeat New Password: <edit var=\"repeatnew\" width=100 height=15><br><br>");
    replyMSG.append("<button value=\"Change Password\" action=\"bypass -h npc_" + getObjectId() + "_change_password $cur $new $repeatnew\" width=204 height=20 back=\"sek.cbui75\" fore=\"sek.cbui75\">");
    replyMSG.append("</center></body></html>");

    nhm.setHtml(replyMSG.toString());
    activeChar.sendPacket(nhm);

    activeChar.sendPacket(new ActionFailed());
  }

  public static boolean changePassword(String currPass, String newPass, String repeatNewPass, L2PcInstance activeChar)
  {
    if (newPass.length() < 5)
    {
      activeChar.sendMessage("The new password is too short!");
      return false;
    }
    if (newPass.length() > 20)
    {
      activeChar.sendMessage("The new password is too long!");
      return false;
    }
    if (!newPass.equals(repeatNewPass))
    {
      activeChar.sendMessage("Repeated password doesn't match the new password.");
      return false;
    }

    Connection con = null;
    String password = null;
    try
    {
      MessageDigest md = MessageDigest.getInstance("SHA");
      byte[] raw = currPass.getBytes("UTF-8");
      raw = md.digest(raw);
      String currPassEncoded = Base64.encodeBytes(raw);

      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts WHERE login=?");
      statement.setString(1, activeChar.getAccountName());
      ResultSet rset = statement.executeQuery();
      while (rset.next())
      {
        password = rset.getString("password");
      }
      rset.close();
      statement.close();
      byte[] password2 =
   null;
      if (currPassEncoded.equals(password))
      {
        password2 = newPass.getBytes("UTF-8");
        password2 = md.digest(password2);

        PreparedStatement statement2 = con.prepareStatement("UPDATE accounts SET password=? WHERE login=?");
        statement2.setString(1, Base64.encodeBytes(password2));
        statement2.setString(2, activeChar.getAccountName());
        statement2.executeUpdate();
        statement2.close();

        activeChar.sendMessage("Congratulations! Your password has been changed succesfully. You will now be disconnected for security reasons. Please login again!");
        try
        {
          Thread.sleep(3000L);
        }
        catch (Exception e)
        {
        }

        activeChar.deleteMe();

        activeChar.sendPacket(new LeaveWorld());
      }
      else
      {
        activeChar.sendMessage("The current password you've inserted is incorrect! Please try again!");
       
        return password2 != null;
      }
    }
    catch (Exception e)
    {
      _log.warning("could not update the password of account: " + activeChar.getAccountName());
    }
    finally
    {
      try
      {
        if (con != null)
          con.close();
      }
      catch (SQLException e)
      {
        _log.warning("Failed to close database connection!");
      }

    }

    return true;
  }
}

  • 0
Posted

Me mia grigori matia pou eri3a den vrika kapio error, ektos an stin DB sou to account_name kai password legonte alios.

 

btw apo ta xirotera code pou exw dei, this.sleep(3000); pano se object gg

  • 0
Posted

Me mia grigori matia pou eri3a den vrika kapio error, ektos an stin DB sou to account_name kai password legonte alios.

 

btw apo ta xirotera code pou exw dei, this.sleep(3000); pano se object gg

Οχι φίλε δεν είναι κάπως αλλιώς στο navicat .. Τι να πω.. Κανένας δεν μπορεί να με help
  • 0
Posted

Γιατί να το βάλεις σε npc όταν μπορείς να το φτιάξεις σε command και να είναι και πιο απλό για τους χρήστες? :) Κάπου έχω τον κώδικα που έχω βάλει στο δικό μου το project... :Ρ

  • 0
Posted

Γιατί να το βάλεις σε npc όταν μπορείς να το φτιάξεις σε command και να είναι και πιο απλό για τους χρήστες? :) Κάπου έχω τον κώδικα που έχω βάλει στο δικό μου το project... :Ρ

Μου κάνει και αυτό αρκεί να μου το στείλεις .. Έψαχνα και command αλλά δεν βρήκα.
Guest
This topic is now closed to further replies.


  • Posts

    • Well, I made this. So if you want to create a talent system design you can always dm me. You can find my contact info here 🙂  
    • como vamos conseguir ler esse arquivos pra salvar ?  
    • DISCORD : https://discord.com/users/325653525793210378 utchiha_market telegram : https://t.me/utchiha_market SELLIX STORE : https://utchihamkt.mysellix.io/ Join our server for more products : https://discord.gg/uthciha-services https://campsite.bio/utchihaamkt
    • Eldamar Don't tell me what to do, stop spamming and mind your own business, it's 2025, who's going to play your server like it's 2007, you're ridiculous.
    • New Season Koofs Vs Noobs Get ready for the return of the epic Lineage II experience! L2KvN is coming back stronger than ever, featuring thrilling PvP, powerful factions, and unforgettable gameplay! Whether you're new to the world of L2KvN or returning to conquer it once more, there’s something for everyone:   Global Launch Times Mark your calendars! The server will launch at the following times around the world 20:00 Greece (Athens) GMT +2  20:00 Russia (Moscow) GMT +3 00:00 Russia (Novosibirsk) GMT +7 05:00 Russia (Vladivostok) GMT +10 14:00 Brazil GMT -3 13:00 Argentina GMT -3 20:00 Lithuania GMT +2 18:00 United Kingdom GMT 0 13:00 USA (Eastern Time) GMT -5 10:00 USA (Pacific Time) GMT -8   L2KvN server is with high rates and custom features. Offers fast progression and an exciting experience. Perfect for fans of intense gameplay.   Server Chronicles Interlude Rates: PvP(High) Adena: x1(Custom) Drop Rate: x1(Custom) 1 PvP = 2 Adena(4 For Premium Users)   Premium Account can be activated by purchasing Premium Account Coupon from L2Store and double-clicking the coupon. Premium Account provides the following: 1 PvP: 4 Adena   General Rates Start up Player System Instant LvL 80 Choose For What Faction You Love To Fight [Koofs - Noobs] Koofs Base: Dark Elf Village Noobs Base: Elven Village Prepare You Character Scheme Buff Or Choose Auto Buff PrePare Your Character Equipment From KvN Shop Killing spree systems Full GM shop. Free class change and Subclass All NPCs available in town. Custom Items Balanced. Community Board BugReport/RaidInfo/TopPvP-Online 1 PvP = 1 Adena (2 If Premium)   Enchant Rates Safe Enchant +6 Max Enchant +21 Normal Scroll Chance: 100% (+0 to +6) Blessed Scroll Chance: 85% (+6 to +21) Ex: If +14 failed for +15, return +14   LifeStone Rates High Lifestone Chance: 5% Top Lifestone Chance: 10%   Grand Bosses Queen Ant 8H +1Random (there is a chance to spawn in 7H or 9H) Drops RB Ring/LS/BOGS Baium 8H +1Random (there is a chance to spawn in 7H or 9H) Drops RB Ring/LS/BOGS Zaken 8H +1Random (there is a chance to spawn in 7H or 9H) Drops RB Ring/LS/BOGS Antharas 8H +1Random (there is a chance to spawn in 7H or 9H) Drops RB Ring/LS/BOGS Valakas 8H +1Random (there is a chance to spawn in 7H or 9H) Drops RB Ring/LS/BOGS   Elo Ranking System start unranked and ranks is Unranked-Iron-Bronze-Silver-Gold-Platinum-Diamond All ranks have 3 rank example Iron III Iron II iron I (iron iii is first and iron i is last. you need iron 1 to upgrade to silver.) unranked to iron need 50 points. and all ranks need 100 points to up a rank 5 points per kill if you die you lose 3 points. if you demote (have 4 points and die and you silver i you will demote to bronze iii 20 points.) if you bronze i 99 points and got 1 kill (+5 points) you uprank to silver iii 20 points. every rank have berets. see in video berets in ranks Iron/Bronze/Silver/Gold/Platinum/Diamond (only visual no extra buffs)   PvP Zone System maps change every 1 hour Orc Village Gludin Town   Event System Events every 1 hour TeamVsTeam => 12:00 14:00 16:00 18:00 20:00 22:00 23:59 02:00 04:00 06:00 08:00 10:00 12:00 Capture The Flag => 13:00 15:00 17:00 19:00 21:00 23:00 01:00 03:00 05:00 07:00 09:00 11:00 Rewards = MvP 5 Events | Winner Team 10 Events | Looser 5 Events   🌐 Website: https://l2kvn.com/ 🌐 Website: https://discord.gg/unn2XBhwef
  • Topics

×
×
  • Create New...