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
006package fc.web.forms;
007
008import javax.servlet.*;
009import javax.servlet.http.*;
010import java.io.*;
011import java.util.*;
012import java.util.regex.*;
013
014import fc.jdbc.*;
015import fc.io.*;
016import fc.util.*;
017
018/**
019Validates two password input boxes to see if they are the
020same. All forms should ask for the password twice when
021signing up the user. 
022<p>
023Automatically resets both password fields if they do not
024match.
025<p>Note, password rules such as required length, characters
026etc., are not checked by this validator. Add a {@link 
027VText} to each password field for that purupose. 
028
029
030@author hursh jain
031**/
032public final class VPasswordGroup extends FormValidator
033{
034Password field_one;
035Password field_two;
036
037/** 
038@param  field_one the first password box
039@param  field_two the second password box
040**/
041public 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
051public 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