Ejemplo n.º 1
0
 /**
  * This saves or overwrites a single security question.
  *
  * @param question the question string
  * @param answer the answer to the question
  * @return true if the question already exsted for the current user
  * @throws GeneralSecurityException if the crypto library cannot be found
  */
 private boolean saveQuestion(String question, String answer, User user)
     throws GeneralSecurityException {
   List<SecurityQuestion> userQuestions = questionDao.getSecurityQuestionsForUser(user);
   boolean found = false;
   for (SecurityQuestion sec : userQuestions) {
     if (sec.getQuestion().equals(question)) {
       questionDao.deleteSecurityQuestion(sec);
       found = true;
       break;
     }
   }
   SecurityQuestion sec = new SecurityQuestion(question, answer, user);
   questionDao.saveOrUpdateSecurityQuestion(sec);
   return found;
 }
Ejemplo n.º 2
0
 /** The mode that lets a user answer their security questions to generate a new password. */
 protected void changeModeRecoverPassword() {
   List<SecurityQuestion> userQuestions = questionDao.getSecurityQuestionsForUser(user);
   if (userQuestions.size() < settings.getRequiredAnswersRange().value()) {
     displayWarningMessage("password.new.no.questions");
     return;
   }
   Object recoverPanel = ui.loadComponentFromFile(XML_RECOVER_PASSWORD, this);
   Object questionsPanel = ui.find(recoverPanel, "questionsPanel");
   Object multiLabel = ui.find(questionsPanel, MULTI_LABEL);
   ui.removeAll(questionsPanel);
   ui.add(questionsPanel, multiLabel);
   questions = new Object[settings.getRequiredQuestionsRange().value()];
   answers = new Object[settings.getRequiredQuestionsRange().value()];
   for (int i = 0; i < questions.length; i++) {
     SecurityQuestion sq = userQuestions.get(i);
     questions[i] = ui.createLabel(sq.getQuestion());
     ui.setAttachedObject(questions[i], sq);
     ui.add(questionsPanel, questions[i]);
     answers[i] = ui.createTextfield("", "");
     ui.add(questionsPanel, answers[i]);
   }
   ui.removeAll(mainPanel);
   ui.add(mainPanel, recoverPanel);
   ui.setFocus(answers[0]);
 }
Ejemplo n.º 3
0
 /** @return the number of security questions for the user */
 private int numberOfSecurityQuestions(User user) {
   return questionDao.getSecurityQuestionsForUser(user).size();
 }