Java tutorial
//package com.java2s; /* * $Id: PassphraseUtils.java 317 2009-01-26 20:20:54Z ronys $ * * Copyright (c) 2008-2009 David Muller <roxon@users.sourceforge.net>. * All rights reserved. Use of the code is allowed under the * Artistic License 2.0 terms, as specified in the LICENSE file * distributed with this code, or available from * http://www.opensource.org/licenses/artistic-license-2.0.php */ public class Main { /** * The minimum length that a password must be to be not weak. */ public static final int MIN_PASSWORD_LEN = 4; /** * Checks the password against a set of rules to determine whether it is * considered weak. The rules are: * </p><p> * <ul> * <li>It is at least <code>MIN_PASSWORD_LEN</code> characters long. * <li>At least one lowercase character. * <li>At least one uppercase character. * <li>At least one digit or symbol character. * </ul> * * @param password the password to check. * * @return <code>true</code> if the password is considered to be weak, * <code>false</code> otherwise. */ public static boolean isWeakPassword(String password) { boolean hasUC = false; boolean hasLC = false; boolean hasDigit = false; boolean hasSymbol = false; if (password.length() < MIN_PASSWORD_LEN) { return true; } for (int ii = 0; ii < password.length(); ++ii) { char c; c = password.charAt(ii); if (Character.isDigit(c)) hasDigit = true; else if (Character.isUpperCase(c)) hasUC = true; else if (Character.isLowerCase(c)) hasLC = true; else hasSymbol = true; } return !(hasUC && hasLC && (hasDigit || hasSymbol)); } }