Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: net.sf.l2j.gameserver.model.actor.instance;PasswordManager.java
- ===================================================================
- --- net.sf.l2j.gameserver.model.actor.instance;PasswordManager.java (revision 84)
- +++ net.sf.l2j.gameserver.model.actor.instance;PasswordManager.java (working copy)
- + package net.sf.l2j.gameserver.model.actor.instance;
- +
- + import java.security.MessageDigest;
- + import java.sql.Connection;
- + import java.sql.PreparedStatement;
- + import java.sql.ResultSet;
- + import java.sql.SQLException;
- + import java.util.Base64;
- + import java.util.StringTokenizer;
- +
- + import net.sf.l2j.L2DatabaseFactory;
- + import net.sf.l2j.gameserver.model.actor.Player;
- + import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
- +
- + public class PasswordManager extends Folk
- + {
- + public PasswordManager(int objectId, NpcTemplate template)
- + {
- + super(objectId, template);
- + }
- +
- + @Override
- + public void onBypassFeedback(Player 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 a password change.");
- + return;
- + }
- +
- + changePassword(currPass, newPass, repeatNewPass, player);
- + }
- + catch (StringIndexOutOfBoundsException e)
- + {
- + e.printStackTrace();
- + }
- + }
- + }
- +
- + @SuppressWarnings("resource")
- + private static boolean changePassword(String currPass, String newPass, String repeatNewPass, Player activeChar)
- + {
- + if (newPass.length() < 3)
- + {
- + 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.getEncoder().encodeToString(raw);
- +
- + con = L2DatabaseFactory.getInstance().getConnection();
- + PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts WHERE login=?");
- + statement.setString(1, activeChar.getAccountName());
- + ResultSet rset = statement.executeQuery();
- +
- + if (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.getEncoder().encodeToString(password2));
- + statement2.setString(2, activeChar.getAccountName());
- + statement2.executeUpdate();
- + statement2.close();
- +
- + activeChar.sendMessage("Your password has been changed succesfully.");
- + }
- + else
- + {
- + activeChar.sendMessage("The password you entered is incorrect. Please try again.");
- +
- + return false;
- + }
- + }
- + catch (Exception e)
- + {
- + LOGGER.info("Could not update the password of account: " + activeChar.getAccountName());
- + }
- + finally
- + {
- + try
- + {
- + if (con != null)
- + con.close();
- + }
- + catch (SQLException e)
- + {
- + LOGGER.info("Failed to close database connection!");
- + }
- +
- + }
- +
- + return true;
- + }
- +
- + @Override
- + public String getHtmlPath(int npcId, int val)
- + {
- + String pom = "";
- + if (val == 0)
- + pom = "" + npcId;
- + else
- + pom = npcId + "-" + val;
- +
- + return "data/html/mods/passwordmanager/" + pom + ".htm";
- + }
- + }
- +
- Index: data/html/mods/passwordmanager/65520.htm
- ===================================================================
- --- data/html/mods/passwordmanager/65520.htm (revision 84)
- +++ data/html/mods/passwordmanager/65520.htm (working copy)
- + <html>
- + <title>Password Manager</title>
- + <body>
- + <center>
- + <table cellpadding=-15 cellspacing=0>
- + <tr>
- + <td width=20></td>
- + <td><img src="TestLogo2.LogoTest2" width=210 height=145></td>
- + </tr>
- + </table>
- + <img src="l2ui.squaregray" width=295 height=2>
- + <table width=295 bgcolor="000000">
- + <tr>
- + </tr>
- + <tr>
- + <td align=center>
- + Current password:
- + <edit var="cur" width=100 height=15>
- + New password:
- + <edit var="new" width=100 height=15>
- + Repeat:
- + <edit var="rep" width=100 height=15>
- + <br>
- + <button value="Change" action="bypass -h npc_%objectId%_change_password $cur $new $rep" width=204 height=19 back="eola.btn_over" fore="eola.btn">
- + </td>
- + </tr>
- + </table>
- + <br><br><br><br>
- + <br><br><br><br>
- + </center>
- + <img src="L2UI.SquareGray" width=295 height=2>
- + <table width=309 bgcolor=000000>
- + <tr>
- + <td align=center><font color="ffc266">www.l2jbrasil.com</font></td>
- + </tr>
- + </table>
- + <img src="L2UI.SquareGray" width=295 height=2>
- + </body>
- + </html>
- Index: data/xml/npc/CustomNpcs.xml
- ===================================================================
- --- data/xml/npc/CustomNpcs.xml (revision 84)
- +++ data/xml/npc/CustomNpcs.xml (working copy)
- + <npc id="65520" idTemplate="30767" name="Sylvas" title="Password Manager">
- + <set name="usingServerSideName" val="true"/>
- + <set name="usingServerSideTitle" val="true"/>
- + <set name="level" val="70"/>
- + <set name="radius" val="8"/>
- + <set name="height" val="22"/>
- + <set name="rHand" val="0"/>
- + <set name="lHand" val="0"/>
- + <set name="type" val="PasswordManager"/>
- + <set name="exp" val="0"/>
- + <set name="sp" val="10"/>
- + <set name="hp" val="2444.46819"/>
- + <set name="mp" val="1345.8"/>
- + <set name="hpRegen" val="7.5"/>
- + <set name="mpRegen" val="2.7"/>
- + <set name="pAtk" val="688.86373"/>
- + <set name="pDef" val="295.91597"/>
- + <set name="mAtk" val="470.40463"/>
- + <set name="mDef" val="216.53847"/>
- + <set name="crit" val="4"/>
- + <set name="atkSpd" val="253"/>
- + <set name="str" val="40"/>
- + <set name="int" val="21"/>
- + <set name="dex" val="30"/>
- + <set name="wit" val="20"/>
- + <set name="con" val="43"/>
- + <set name="men" val="20"/>
- + <set name="corpseTime" val="7"/>
- + <set name="walkSpd" val="80"/>
- + <set name="runSpd" val="120"/>
- + <set name="dropHerbGroup" val="0"/>
- + <set name="attackRange" val="40"/>
- + <ai type="DEFAULT" ssCount="0" ssRate="0" spsCount="0" spsRate="0" aggro="0" canMove="true" seedable="false"/>
- + <skills>
- + <skill id="4045" level="1"/>
- + <skill id="4416" level="7"/>
- + </skills>
- + </npc>
Add Comment
Please, Sign In to add comment