SHOW:
|
|
- or go back to the newest paste.
1 | Index: net.sf.l2j.gameserver.model.actor.instance;PasswordManager.java | |
2 | =================================================================== | |
3 | --- net.sf.l2j.gameserver.model.actor.instance;PasswordManager.java (revision 84) | |
4 | +++ net.sf.l2j.gameserver.model.actor.instance;PasswordManager.java (working copy) | |
5 | ||
6 | + package net.sf.l2j.gameserver.model.actor.instance; | |
7 | + | |
8 | + import java.security.MessageDigest; | |
9 | + import java.sql.Connection; | |
10 | + import java.sql.PreparedStatement; | |
11 | + import java.sql.ResultSet; | |
12 | + import java.sql.SQLException; | |
13 | + import java.util.Base64; | |
14 | + import java.util.StringTokenizer; | |
15 | + | |
16 | + import net.sf.l2j.L2DatabaseFactory; | |
17 | + import net.sf.l2j.gameserver.model.actor.Player; | |
18 | + import net.sf.l2j.gameserver.model.actor.template.NpcTemplate; | |
19 | + | |
20 | + public class PasswordManager extends Folk | |
21 | + { | |
22 | + public PasswordManager(int objectId, NpcTemplate template) | |
23 | + { | |
24 | + super(objectId, template); | |
25 | + } | |
26 | + | |
27 | + @Override | |
28 | + public void onBypassFeedback(Player player, String command) | |
29 | + { | |
30 | + if (command.startsWith("change_password")) | |
31 | + { | |
32 | + StringTokenizer st = new StringTokenizer(command); | |
33 | + st.nextToken(); | |
34 | + String currPass = null; | |
35 | + String newPass = null; | |
36 | + String repeatNewPass = null; | |
37 | + try | |
38 | + { | |
39 | + if (st.hasMoreTokens()) | |
40 | + { | |
41 | + currPass = st.nextToken(); | |
42 | + newPass = st.nextToken(); | |
43 | + repeatNewPass = st.nextToken(); | |
44 | + } | |
45 | + else | |
46 | + { | |
47 | + player.sendMessage("Please fill in all the blanks before requesting a password change."); | |
48 | + return; | |
49 | + } | |
50 | + | |
51 | + changePassword(currPass, newPass, repeatNewPass, player); | |
52 | + } | |
53 | + catch (StringIndexOutOfBoundsException e) | |
54 | + { | |
55 | + e.printStackTrace(); | |
56 | + } | |
57 | + } | |
58 | + } | |
59 | + | |
60 | + @SuppressWarnings("resource") | |
61 | + private static boolean changePassword(String currPass, String newPass, String repeatNewPass, Player activeChar) | |
62 | + { | |
63 | + if (newPass.length() < 3) | |
64 | + { | |
65 | + activeChar.sendMessage("The new password is too short."); | |
66 | + return false; | |
67 | + } | |
68 | + if (newPass.length() > 20) | |
69 | + { | |
70 | + activeChar.sendMessage("The new password is too long."); | |
71 | + return false; | |
72 | + } | |
73 | + if (!newPass.equals(repeatNewPass)) | |
74 | + { | |
75 | + activeChar.sendMessage("Repeated password doesn't match the new password."); | |
76 | + return false; | |
77 | + } | |
78 | + | |
79 | + Connection con = null; | |
80 | + String password = null; | |
81 | + try | |
82 | + { | |
83 | + MessageDigest md = MessageDigest.getInstance("SHA"); | |
84 | + byte[] raw = currPass.getBytes("UTF-8"); | |
85 | + raw = md.digest(raw); | |
86 | + String currPassEncoded = Base64.getEncoder().encodeToString(raw); | |
87 | + | |
88 | + con = L2DatabaseFactory.getInstance().getConnection(); | |
89 | + PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts WHERE login=?"); | |
90 | + statement.setString(1, activeChar.getAccountName()); | |
91 | + ResultSet rset = statement.executeQuery(); | |
92 | + | |
93 | + if (rset.next()) | |
94 | + { | |
95 | + password = rset.getString("password"); | |
96 | + } | |
97 | + | |
98 | + rset.close(); | |
99 | + statement.close(); | |
100 | + byte[] password2 = null; | |
101 | + | |
102 | + if (currPassEncoded.equals(password)) | |
103 | + { | |
104 | + password2 = newPass.getBytes("UTF-8"); | |
105 | + password2 = md.digest(password2); | |
106 | + | |
107 | + PreparedStatement statement2 = con.prepareStatement("UPDATE accounts SET password=? WHERE login=?"); | |
108 | + statement2.setString(1, Base64.getEncoder().encodeToString(password2)); | |
109 | + statement2.setString(2, activeChar.getAccountName()); | |
110 | + statement2.executeUpdate(); | |
111 | + statement2.close(); | |
112 | + | |
113 | + activeChar.sendMessage("Your password has been changed succesfully."); | |
114 | + } | |
115 | + else | |
116 | + { | |
117 | + activeChar.sendMessage("The password you entered is incorrect. Please try again."); | |
118 | + | |
119 | + return false; | |
120 | + } | |
121 | + } | |
122 | + catch (Exception e) | |
123 | + { | |
124 | + LOGGER.info("Could not update the password of account: " + activeChar.getAccountName()); | |
125 | + } | |
126 | + finally | |
127 | + { | |
128 | + try | |
129 | + { | |
130 | + if (con != null) | |
131 | + con.close(); | |
132 | + } | |
133 | + catch (SQLException e) | |
134 | + { | |
135 | + LOGGER.info("Failed to close database connection!"); | |
136 | + } | |
137 | + | |
138 | + } | |
139 | + | |
140 | + return true; | |
141 | + } | |
142 | + | |
143 | + @Override | |
144 | + public String getHtmlPath(int npcId, int val) | |
145 | + { | |
146 | + String pom = ""; | |
147 | + if (val == 0) | |
148 | + pom = "" + npcId; | |
149 | + else | |
150 | + pom = npcId + "-" + val; | |
151 | + | |
152 | + return "data/html/mods/passwordmanager/" + pom + ".htm"; | |
153 | + } | |
154 | + } | |
155 | + | |
156 | ||
157 | Index: data/html/mods/passwordmanager/65520.htm | |
158 | =================================================================== | |
159 | --- data/html/mods/passwordmanager/65520.htm (revision 84) | |
160 | +++ data/html/mods/passwordmanager/65520.htm (working copy) | |
161 | ||
162 | ||
163 | + <html> | |
164 | + <title>Password Manager</title> | |
165 | + <body> | |
166 | + <center> | |
167 | + <table cellpadding=-15 cellspacing=0> | |
168 | + <tr> | |
169 | + <td width=20></td> | |
170 | + <td><img src="TestLogo2.LogoTest2" width=210 height=145></td> | |
171 | + </tr> | |
172 | + </table> | |
173 | + <img src="l2ui.squaregray" width=295 height=2> | |
174 | + <table width=295 bgcolor="000000"> | |
175 | + <tr> | |
176 | + </tr> | |
177 | + <tr> | |
178 | + <td align=center> | |
179 | + Current password: | |
180 | + <edit var="cur" width=100 height=15> | |
181 | + New password: | |
182 | + <edit var="new" width=100 height=15> | |
183 | + Repeat: | |
184 | + <edit var="rep" width=100 height=15> | |
185 | + <br> | |
186 | + <button value="Change" action="bypass -h npc_%objectId%_change_password $cur $new $rep" width=204 height=19 back="eola.btn_over" fore="eola.btn"> | |
187 | + </td> | |
188 | + </tr> | |
189 | + </table> | |
190 | + <br><br><br><br> | |
191 | + <br><br><br><br> | |
192 | + </center> | |
193 | + <img src="L2UI.SquareGray" width=295 height=2> | |
194 | + <table width=309 bgcolor=000000> | |
195 | + <tr> | |
196 | + <td align=center><font color="ffc266">www.l2jbrasil.com</font></td> | |
197 | + </tr> | |
198 | + </table> | |
199 | + <img src="L2UI.SquareGray" width=295 height=2> | |
200 | + </body> | |
201 | + </html> | |
202 | ||
203 | ||
204 | Index: data/xml/npc/CustomNpcs.xml | |
205 | =================================================================== | |
206 | --- data/xml/npc/CustomNpcs.xml (revision 84) | |
207 | +++ data/xml/npc/CustomNpcs.xml (working copy) | |
208 | ||
209 | + <npc id="65520" idTemplate="30767" name="Sylvas" title="Password Manager"> | |
210 | + <set name="usingServerSideName" val="true"/> | |
211 | + <set name="usingServerSideTitle" val="true"/> | |
212 | + <set name="level" val="70"/> | |
213 | + <set name="radius" val="8"/> | |
214 | + <set name="height" val="22"/> | |
215 | + <set name="rHand" val="0"/> | |
216 | + <set name="lHand" val="0"/> | |
217 | + <set name="type" val="PasswordManager"/> | |
218 | + <set name="exp" val="0"/> | |
219 | + <set name="sp" val="10"/> | |
220 | + <set name="hp" val="2444.46819"/> | |
221 | + <set name="mp" val="1345.8"/> | |
222 | + <set name="hpRegen" val="7.5"/> | |
223 | + <set name="mpRegen" val="2.7"/> | |
224 | + <set name="pAtk" val="688.86373"/> | |
225 | + <set name="pDef" val="295.91597"/> | |
226 | + <set name="mAtk" val="470.40463"/> | |
227 | + <set name="mDef" val="216.53847"/> | |
228 | + <set name="crit" val="4"/> | |
229 | + <set name="atkSpd" val="253"/> | |
230 | + <set name="str" val="40"/> | |
231 | + <set name="int" val="21"/> | |
232 | + <set name="dex" val="30"/> | |
233 | + <set name="wit" val="20"/> | |
234 | + <set name="con" val="43"/> | |
235 | + <set name="men" val="20"/> | |
236 | + <set name="corpseTime" val="7"/> | |
237 | + <set name="walkSpd" val="80"/> | |
238 | + <set name="runSpd" val="120"/> | |
239 | + <set name="dropHerbGroup" val="0"/> | |
240 | + <set name="attackRange" val="40"/> | |
241 | + <ai type="DEFAULT" ssCount="0" ssRate="0" spsCount="0" spsRate="0" aggro="0" canMove="true" seedable="false"/> | |
242 | + <skills> | |
243 | + <skill id="4045" level="1"/> | |
244 | + <skill id="4416" level="7"/> | |
245 | + </skills> | |
246 | + </npc> |