1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8*9* http://www.apache.org/licenses/LICENSE-2.010*11* Unless required by applicable law or agreed to in writing, software12* distributed under the License is distributed on an "AS IS" BASIS,13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14* See the License for the specific language governing permissions and15* limitations under the License.16*/17packageorg.apache.jetspeed.security.spi.impl;
1819import org.apache.jetspeed.security.InvalidPasswordException;
20import org.apache.jetspeed.security.SecurityException;
21import org.apache.jetspeed.security.spi.CredentialPasswordValidator;
2223/***24 * <p>25 * SimpleCredentialPasswordValidator26 * </p>27 * 28 * @author <a href="mailto:ate@apache.org">Ate Douma</a>29 * @version $Id: SimpleCredentialPasswordValidator.java 516448 2007-03-09 16:25:47Z ate $30 */31publicclassSimpleCredentialPasswordValidator implements CredentialPasswordValidator
32 {
33privateint minPasswordLength;
34privateint minNumberOfDigits;
3536/***37 * @param minPasswordLength38 * @param minNumberOfDigits39 */40publicSimpleCredentialPasswordValidator(int minPasswordLength, int minNumberOfDigits)
41 {
42this.minPasswordLength = minPasswordLength;
43this.minNumberOfDigits = minNumberOfDigits;
44 }
4546/***47 * @see org.apache.jetspeed.security.spi.CredentialPasswordValidator#validate(String)48 */49publicvoid validate(String clearTextPassword) throws SecurityException
50 {
51int digits = 0;
52if ( clearTextPassword == null )
53 {
54 clearTextPassword = "";
55 }
56char[] pwd = clearTextPassword.toCharArray();
5758if ( minPasswordLength > 0 && pwd.length < minPasswordLength )
59 {
60thrownew InvalidPasswordException();
61 }
6263if ( minNumberOfDigits > 0)
64 {
65for ( int i = 0; i < pwd.length; i++ )
66 {
67if (Character.isDigit(pwd[i]))
68 {
69 digits++;
70 }
71 }
72if (digits < minNumberOfDigits)
73 {
74thrownew InvalidPasswordException();
75 }
76 }
77 }
78 }