public boolean savePassword(String password) { if (passwordExist()) { _log.warning( "[SecondaryPasswordAuth]" + _activeClient.getAccountName() + " forced savePassword"); _activeClient.closeNow(); return false; } if (!validatePassword(password)) { _activeClient.sendPacket(new Ex2ndPasswordAck(Ex2ndPasswordAck.WRONG_PATTERN)); return false; } password = cryptPassword(password); Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(INSERT_PASSWORD); statement.setString(1, _activeClient.getAccountName()); statement.setString(2, VAR_PWD); statement.setString(3, password); statement.execute(); statement.close(); } catch (Exception e) { _log.log(Level.SEVERE, "Error while writing password.", e); return false; } finally { L2DatabaseFactory.close(con); } _password = password; return true; }
public boolean changePassword(String oldPassword, String newPassword) { if (!passwordExist()) { _log.warning( "[SecondaryPasswordAuth]" + _activeClient.getAccountName() + " forced changePassword"); _activeClient.closeNow(); return false; } if (!checkPassword(oldPassword, true)) return false; if (!validatePassword(newPassword)) { _activeClient.sendPacket(new Ex2ndPasswordAck(Ex2ndPasswordAck.WRONG_PATTERN)); return false; } newPassword = cryptPassword(newPassword); Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(UPDATE_PASSWORD); statement.setString(1, newPassword); statement.setString(2, _activeClient.getAccountName()); statement.setString(3, VAR_PWD); statement.execute(); statement.close(); } catch (Exception e) { _log.log(Level.SEVERE, "Error while reading password.", e); return false; } finally { L2DatabaseFactory.close(con); } _password = newPassword; _authed = false; return true; }