/build/distribution/IzPack/sample/src/PWDValidator.java
Java | 77 lines | 23 code | 7 blank | 47 comment | 3 complexity | cdc8da389a2d55ff6784b350d45f516e MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
1/*
2 * $Id: PWDValidator.java 5819 2006-06-14 07:29:09Z cesar $
3 * Copyright (C) 2003 Elmar Grom
4 *
5 * File : PWDValidator.java
6 * Description : Example implementation of a password validator
7 * Author's email : elmar@grom.net
8 * Author's Website : http://www.izforge.com
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25package com.izforge.izpack.sample;
26
27import com.izforge.izpack.panels.*;
28
29/*---------------------------------------------------------------------------*/
30/**
31 * This class represents a simple validator for passwords to demonstrate
32 * the implementation of a password validator that cooperates with the
33 * password field in the <code>UserInputPanel</code>
34 *
35 * @version 0.0.1 / 02/19/03
36 * @author Elmar Grom
37 */
38/*---------------------------------------------------------------------------*/
39public class PWDValidator implements Validator
40{
41 /*--------------------------------------------------------------------------*/
42 /**
43 * Validates the contend of multiple password fields. The test
44 *
45 * @param client the client object using the services of this validator.
46 *
47 * @return <code>true</code> if the validation passes, otherwise <code>false</code>.
48 */
49 /*--------------------------------------------------------------------------*/
50 public boolean validate (ProcessingClient client)
51 {
52 int numFields = client.getNumFields ();
53
54 // ----------------------------------------------------
55 // verify that there is more than one field. If there
56 // is only one field we have to return true.
57 // ----------------------------------------------------
58 if (numFields < 2)
59 {
60 return (true);
61 }
62
63 boolean match = true;
64 String content = client.getFieldContents (0);
65
66 for (int i = 1; i < numFields; i++)
67 {
68 if (!content.equals (client.getFieldContents (i)))
69 {
70 match = false;
71 }
72 }
73
74 return (match);
75 }
76}
77/*---------------------------------------------------------------------------*/