public PasswordCheckResult check ( boolean isAdminitrative , String userName , String password ) { // TODO: allow custom restrictions? List < PasswordRestriction > passwordValuesRestrictions = getPasswordRestrictions ( ) ; final PasswordStrengthCheckResult strengthResult = this . passwordStrengthChecker . check ( userName , password , passwordValuesRestrictions ) ; final int failedRestrictions = strengthResult . getRestrictionFailures ( ) . size ( ) ; final PasswordStrength strength = strengthResult . getStrength ( ) ; final boolean strongEnough = assertStrength ( strength ) ; PasswordCheckResult . Result resultAction ; String resultMessage = null ; if ( isAdminitrative ) { if ( strongEnough ) { if ( failedRestrictions > 0 ) { resultAction = Result . WARN ; resultMessage = strengthResult . getRestrictionFailures ( ) . get ( 0 ) . getMessage ( ) ; } else { resultAction = Result . ACCEPT ; } } else { resultAction = Result . WARN ; resultMessage = ROOT_LOGGER . passwordNotStrongEnough ( strength . toString ( ) , this . acceptable . toString ( ) ) ; } } else { if ( strongEnough ) { if ( failedRestrictions > 0 ) { resultAction = Result . REJECT ; resultMessage = strengthResult . getRestrictionFailures ( ) . get ( 0 ) . getMessage ( ) ; } else { resultAction = Result . ACCEPT ; } } else { if ( failedRestrictions > 0 ) { resultAction = Result . REJECT ; resultMessage = strengthResult . getRestrictionFailures ( ) . get ( 0 ) . getMessage ( ) ; } else { resultAction = Result . REJECT ; resultMessage = ROOT_LOGGER . passwordNotStrongEnough ( strength . toString ( ) , this . acceptable . toString ( ) ) ; } } } return new PasswordCheckResult ( resultAction , resultMessage ) ; }
Method which performs strength checks on password . It returns outcome which can be used by CLI .