// ========================================================================== private boolean validateLogin() { boolean flag = false; String user = null; String password = null; try { user = jxlp.getUserName(); password = new String(jxlp.getPassword()); if (user == null || user.length() < 1) { jxlp.setMessage("user name is empty"); return false; } if (password == null || password.length() < 1) { jxlp.setMessage("password is empty"); return false; } flag = new ControllerAuthentication().login(user, password); if (!flag) { jxlp.setMessage("user or password are incorrect"); return false; } } catch (Exception e) { notifications.error("error while autenticate the user", e); } createUser(user); return flag; } // end validateLogin
public static void show() { configure(); final LoginService loginService = new SimpleLoginService(); ServerHandler serverHandler = new ServerHandler(); DefaultUserNameStore userNames = new DefaultUserNameStore(); Preferences appPrefs = Preferences.userNodeForPackage(TestLogin.class); userNames.setPreferences(appPrefs.node("login")); List<Server> servers = serverHandler.getServers(); // serverHandler.adjustServers(servers, "Test Server"); ((SimpleLoginService) loginService).setServers(servers); List<String> list = serverHandler.getServerNames(servers); final JXLoginPane panel = new JXLoginPane(loginService, null, userNames, list); // panel.setUserName("mihai"); panel.setBannerText("Reportz Login"); // overwrite login failed message loginService.addLoginListener( new LoginAdapter() { public void loginFailed(LoginEvent event) { String defaultMessage = "<html><b>Couldn't log in</b><br><br>Check your user name and password.<br></html>"; String message = event.getCause() != null ? event.getCause().getMessage() : defaultMessage; panel.setErrorMessage(message); } }); final JXLoginPane.JXLoginFrame frame = JXLoginPane.showLoginFrame(panel); frame.addWindowListener( new WindowAdapter() { public void windowClosed(java.awt.event.WindowEvent e) { if (frame.getStatus() == JXLoginPane.Status.SUCCEEDED) { System.out.println("Login Succeeded!"); } else { System.out.println("Login Failed:" + frame.getStatus()); } System.exit(0); } }); frame.setVisible(true); }
// ========================================================================== private boolean checkPassword() { boolean flag = true; try { char password[] = jxlp.getPassword(); for (int i = 0; i < password.length; i++) { char c = password[i]; // Si no es letra o numero entonces no es valido if (!Character.isLetterOrDigit(c)) { flag = false; break; } } } catch (Exception e) { notifications.error("An error has occurred in the application", e); } return flag; } // end checkPassword