} while (true) { try { FritzBoxFirmware.detectFirmwareVersion(JFritz .getProperty("box.address"), Encryption .decrypt(JFritz .getProperty("box.password"))); password = Encryption.decrypt(JFritz .getProperty("box.password")); break; } catch (WrongPasswordException e1) { Debug.err("Password wrong!"); jfritz.getJframe().setStatus( JFritz.getMessage("password_wrong")); jfritz.getJframe().setBusy(false);
	private int login(String user, String password) {		try {			Debug.msg("Login to Telnet");			String login = "ogin: ";			String passwd = "assword: ";			boolean firstLogin = true;			boolean firstPassword = true;			char lastCharLogin = login.charAt(login.length() - 1);			char lastCharPasswd = passwd.charAt(passwd.length() - 1);			StringBuffer sb = new StringBuffer();			char ch = (char) in.read();			while (true) {				sb.append(ch); // FIXME This can be done better!!!				if (ch == lastCharLogin || ch == lastCharPasswd || ch == prompt) {					if (sb.toString().endsWith(login)) {						// wenn Fehlgeschlagen, dann						// mehrmaliges Login mit falschem						// Username verhindern						if (firstLogin) {							Debug.msg("Writing Telnet User: " + user);							write(user);							firstLogin = false;						} else {							TelnetConfigDialog telnetConfigDialog = new TelnetConfigDialog(									jfritz.getJframe(), jfritz);							telnetConfigDialog.setModal(true);							if (telnetConfigDialog.showTelnetConfigDialog() == TelnetConfigDialog.CANCEL_OPTION) {								//ABBRUCH								jfritz.stopCallMonitor();								return LOGIN_CANCELED;							}						}					}					if (sb.toString().endsWith(passwd)) {						// schauen, ob WebPasswort abgefragt wird						if (sb.toString().endsWith("web password: ")) {							password = Encryption.decrypt(JFritz									.getProperty("box.password"));						}						while (true) { // test WebPassword							try {								FritzBoxFirmware.detectFirmwareVersion(JFritz										.getProperty("box.address"), Encryption										.decrypt(JFritz												.getProperty("box.password")));								password = Encryption.decrypt(JFritz										.getProperty("box.password"));								break; // go on with telnet login							} catch (WrongPasswordException e1) {								Debug.err("Password wrong!");								jfritz.getJframe().setStatus(										JFritz.getMessage("password_wrong"));								jfritz.getJframe().setBusy(false);								String newPassword = jfritz.getJframe()										.showPasswordDialog(												Encryption.decrypt(JFritz														.getProperty(																"box.password",																"")));								System.out.println("OLD PASS: "										+ Encryption												.decrypt(JFritz.getProperty(														"box.password", "")));								if (newPassword == null) { // Dialog aborted									jfritz.stopCallMonitor();									return LOGIN_CANCELED;								} else {									JFritz.setProperty("box.password",											Encryption.encrypt(newPassword));								}							}						}						// wenn Fehlgeschlagen, dann						// mehrmaliges Login mit falschem						// Passwort verhindern						if (firstPassword) {							Debug.msg("Writing Telnet Password: " + password);							write(password);							firstPassword = false;						} else {							TelnetConfigDialog telnetConfigDialog = new TelnetConfigDialog(									jfritz.getJframe(), jfritz);							telnetConfigDialog.setModal(true);							if (telnetConfigDialog.showTelnetConfigDialog() == TelnetConfigDialog.CANCEL_OPTION) {								//ABBRUCH								return LOGIN_CANCELED;							}						}					}					if (ch == prompt) {						System.err.println(sb.toString());						break;					}				}				ch = (char) in.read();			}		} catch (Exception e) {			Debug.err(e.getMessage());		}		Debug.msg("Logged into Telnet connection.");		return LOGIN_OK;	}