Пример #1
0
 /**
  * The callback method for users creating new security questions.
  *
  * @throws GeneralSecurityException if the crypto libray cannot be loaded
  */
 public void attemptSaveQuestions() throws GeneralSecurityException {
   // TODO: error handling
   if (questions == null || answers == null) {
     ui.createDialog(getI18NString("password.new.warning"));
     return;
   }
   for (int i = 0; i < questions.length; i++) {
     String q = ui.getText(questions[i]);
     String a = ui.getText(answers[i]);
     if (q != null && !q.equals("") && a != null && !a.equals("")) {
       // delete the question if it is alreay there
       saveQuestion(q, a, user);
     }
   }
   int count = numberOfSecurityQuestions(user);
   int requiredQuestions = settings.getRequiredQuestionsRange().value();
   if (count < requiredQuestions) {
     Object label = ui.find(mainPanel, MULTI_LABEL);
     String text;
     if (count == 1) {
       text = getI18NString(QUESTION_ON_FILE);
     } else {
       text = getI18NString(QUESTIONS_ON_FILE);
       text = text.replaceAll("<X>", "" + count);
     }
     int req = requiredQuestions - count;
     text = text.replaceFirst("<Y>", "" + req);
     ui.setText(label, text);
   } else {
     answers = null;
     questions = null;
     changeModePatientView();
   }
 }
Пример #2
0
 /** The callback method for the forgot password link on the landing screen. */
 public void attemptForgotPassword() {
   Object usernameField = ui.find(mainPanel, "usernameField");
   String username = ui.getText(usernameField);
   if (username != null) {
     user = userDao.getUserByUsername(username);
     if (user != null) {
       changeModeRecoverPassword();
     } else {
       displayWarningMessage(INVALID_USER_MESSAGE);
     }
   } else {
     displayWarningMessage(INVALID_USER_MESSAGE);
   }
 }
Пример #3
0
 /**
  * The callback method for users creating a new password.
  *
  * @throws GeneralSecurityException if the crypto libray cannot be loaded
  */
 public void attemptSavePassword() throws GeneralSecurityException {
   // TODO: error handling
   Object passwordBox = ui.find(mainPanel, "password1");
   String pass1 = ui.getText(passwordBox);
   passwordBox = ui.find(mainPanel, "password2");
   String pass2 = ui.getText(passwordBox);
   if (pass1.equals(pass2)) {
     if (PasswordUtils.passwordMeetsRequirements(pass1)) {
       user.setPassword(pass1);
       userDao.updateUser(user);
       if (numberOfSecurityQuestions(user) < settings.getRequiredQuestionsRange().value()) {
         changeModeNewQuestions();
       } else {
         resetSoft();
         Object label = ui.find(mainPanel, "multiLabel");
         ui.setText(label, getI18NString("password.new.use"));
       }
     } else {
       displayWarningMessage("password.new.warning.criteria");
     }
   } else {
     displayWarningMessage("password.new.warning.match");
   }
 }
Пример #4
0
 /**
  * The callback function for when a user attempts to recover their security questions by answering
  * their security questions.
  *
  * @throws GeneralSecurityException
  */
 public void attemptRecoverPassword() throws GeneralSecurityException {
   // TODO: error handling
   int correct = 0;
   for (int i = 0; i < questions.length; i++) {
     String a = ui.getText(answers[i]);
     // find the SecurityQuestion object that corrosponds to the string
     SecurityQuestion sq = ui.getAttachedObject(questions[i], SecurityQuestion.class);
     if (sq.verifyAnswer(a)) {
       correct++;
     }
   }
   System.out.println(correct);
   if (correct >= settings.getRequiredAnswersRange().value()) {
     changeModeNewPassword();
   } else {
     Object label = ui.find(mainPanel, MULTI_LABEL);
     String text = getI18NString("password.reset.wrong.answer");
     // text = text.replaceFirst("<X>", "" );
     ui.setText(label, text);
   }
 }
Пример #5
0
 /** The callback method for when a user preses a login button in this screen. */
 public void attemptLogin() {
   Object usernameField = ui.find(mainPanel, "usernameField");
   Object passwordField = ui.find(mainPanel, "passwordField");
   String username = ui.getText(usernameField);
   String password = ui.getText(passwordField);
   UserSessionManager manager = UserSessionManager.getUserSessionManager();
   AuthenticationResult result = manager.login(username, password);
   if (result == AuthenticationResult.NOSUCHUSER || result == AuthenticationResult.WRONGPASSWORD) {
     displayWarningMessage(INCORRECT_LOGIN_MESSAGE);
   }
   if (result == AuthenticationResult.SUCCESS) {
     user = manager.getCurrentUser();
     if (user.needsNewPassword()) {
       changeModeNewPassword();
     } else if (numberOfSecurityQuestions(user) < settings.getRequiredQuestionsRange().value()) {
       changeModeNewQuestions();
     } else {
       changeModePatientView();
     }
   }
 }