@Override public Optional<User> verify(String value, Tenant tenant) { final int space = value.indexOf(' '); if (space > 0) { final String decoded = B64Code.decode(value.substring(space + 1), StringUtil.__ISO_8859_1); final int i = decoded.indexOf(':'); if (i > 0) { final String username = decoded.substring(0, i); final String password = decoded.substring(i + 1); User user = userStore.get().findUserByEmailOrUserName(username); if (user != null) { if (this.passwordManager.verifyPassword(password, user.getPassword())) { return Optional.of(user); } } } } return Optional.absent(); } }
User user = userStore.get().findUserByEmailOrUserName(username); if (user != null) { if (this.passwordManager.verifyPassword(password, user.getPassword())) { return Optional.of(user);
@Override public void changePassword(User user, String currentPassword, String newPassword) throws WrongPasswordException, PasswordDoesNotMeetRequirementsException { Preconditions.checkNotNull(user); Preconditions.checkNotNull(user.getId()); User stored = this.userStore.get().findById(user.getId()); if (!this.passwordManager.verifyPassword(currentPassword, stored.getPassword())) { throw new WrongPasswordException("Refusing to change password : given current password is incorrect"); } if (!passwordStrengthChecker.checkLength(newPassword)) { throw new PasswordDoesNotMeetRequirementsException( "Provided password does not meet requirements : length too short"); } if (!passwordStrengthChecker.checkEntropy(newPassword)) { throw new PasswordDoesNotMeetRequirementsException( "Provided password does not meet requirements : not enough bits of entropy"); } this.userStore.get().updatePassword(user, passwordManager.hashPassword(newPassword)); }
private void create(User user, Role initialRole, Map<String, Object> additionalContext) throws InvalidEntityException, EntityAlreadyExistsException, PasswordDoesNotMeetRequirementsException { AccountsSettings settings = getSettings(); Boolean validationIsRequired = settings.getUserValidation().getValue(); if (user.getPassword().length() < settings.getPasswordRequirements().getMinimalLength()) { throw new PasswordDoesNotMeetRequirementsException("Provided password does not meet requirements"); } if (validationIsRequired) { if (context.getTenant() != null) { throw new RuntimeException("Validation is not supported for local users"); } user.setActive(false); user.setValidationKey(generateSecret()); } else { user.setActive(true); } user.setPassword(this.passwordManager.hashPassword(user.getPassword())); final User createdUser = this.userStore.get().create(user, initialRole); if (validationIsRequired) { sendValidationMail(createdUser, settings, additionalContext); } }