/** * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations under * the License. * * The Original Code is OpenELIS code. * * Copyright (C) The Minnesota Department of Health. All Rights Reserved. * * Contributor(s): CIRG, University of Washington, Seattle WA. */ package us.mn.state.health.lims.common.provider.validation; import org.apache.commons.validator.GenericValidator; import us.mn.state.health.lims.common.util.StringUtil; import java.util.regex.Pattern; public class HaitiPasswordValidation implements ILoginPasswordValidation { /* Current Haiti requirements * # Password must:be at least 7 characters long * # contain only upper or lower case characters * # numbers * # must have at least one of the following characters (*,$,#,!) * */ private static final Pattern NEGATION_Of_MUST_ONLY_CONTAIN = Pattern.compile("[^\\w*$#!]"); private static final Pattern SPECIAL_CHARS = Pattern.compile("[*$#!]+"); public boolean passwordValid(String password) { //make sure it is long enough and //make sure it only contains the characters we want and //make sure it contains at least one special character return !GenericValidator.isBlankOrNull(password) && password.length() >= 7 && !NEGATION_Of_MUST_ONLY_CONTAIN.matcher(password).find() && SPECIAL_CHARS.matcher(password).find(); } public String getInstructions() { return StringUtil.getMessageForKey("login.complexity.message"); } }