001 // Copyright (c) 2001 Hursh Jain (http://www.mollypages.org) 002 // The Molly framework is freely distributable under the terms of an 003 // MIT-style license. For details, see the molly pages web site at: 004 // http://www.mollypages.org/. Use, modify, have fun ! 005 006 package fc.web.forms; 007 008 import javax.servlet.*; 009 import javax.servlet.http.*; 010 import java.io.*; 011 import java.util.*; 012 import java.util.regex.*; 013 014 import fc.jdbc.*; 015 import fc.io.*; 016 import fc.util.*; 017 018 /** 019 Validates two password input boxes to see if they are the 020 same. All forms should ask for the password twice when 021 signing up the user. 022 <p> 023 Automatically resets both password fields if they do not 024 match. 025 <p>Note, password rules such as required length, characters 026 etc., are not checked by this validator. Add a {@link 027 VText} to each password field for that purupose. 028 029 030 @author hursh jain 031 **/ 032 public final class VPasswordGroup extends FormValidator 033 { 034 Password field_one; 035 Password field_two; 036 037 /** 038 @param field_one the first password box 039 @param field_two the second password box 040 **/ 041 public VPasswordGroup(Form f, String name, String errorMessage, 042 Password field_one, Password field_two) 043 { 044 super(f, name, errorMessage); 045 Argcheck.notnull(field_one, "parm field_one was null"); 046 Argcheck.notnull(field_two, "parm field_two was null"); 047 this.field_one = field_one; 048 this.field_two = field_two; 049 } 050 051 public boolean validate(FormData fd, HttpServletRequest req) 052 { 053 String one = field_one.getValue(fd); 054 String two = field_two.getValue(fd); 055 boolean result = false; 056 057 //System.out.println(">>>> 1=[" + one + "]; 2=[" + two + "]"); 058 if ( one != null && one.equals(two) ) 059 result = true; 060 061 if (! result) { 062 field_one.reset(fd); 063 field_two.reset(fd); 064 } 065 return result; 066 } 067 068 } //~class VPasswordGroup 069