Password confirmation using Zend Form and Validators

A while back i needed a password confirmation field for my users. I looked and found this neat little snippet. I cant remember who created it originally so i cant give credits to the person but its quite easy to use. Just add this to your library and create a new validator object like this.

This would be in your form where you want to have password confirmation.

About Christian Kirkegaard

i like π
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

8 Responses to Password confirmation using Zend Form and Validators

  1. Pingback: Zend Framework in Action » Christian Kirkegaard: Password confirmation using Zend Form and Validators

  2. Nice!

    It would be more general purpose if you could configure the validator with the names of the two password fields. Maybe passed in the constructor?

    Thanks for a great snippet. ;-)

  3. Cory Wiles says:

    My friend Jeremy Kendall (http://www.jeremykendall.net) and I worked on this.

  4. Pingback: Zend Framework News » Blog Archive » Passwortvalidierung mit Zend_Form und Zend_Validator

  5. Marcus says:

    Original script is from this tutorial by Andrei Nikolov: http://zfsite.andreinikolov.com/2008/05/part-4-zendform-captcha-password-confirmation-date-selector-field-zendtranslate/

  6. Pingback: Linkpool Nummer 5 | PHP Gangsta - Der PHP Blog

  7. roti says:

    Im getting the Not match always, even if I put same passwords in both of the textbox..

    MyValidatePasswordConfirmation

    const NOT_MATCH = ‘notMatch’;

    protected $messageTemplates = array(self::NOTMATCH => 'Passwords do

    not match.’);

    public function isValid($value, $context = null) { $value = (string) $value; $this->_setValue($value);

            if (is_array($context)) {
                    if (isset($context['confirmation']) && ($value ==$context['confirmation'])) {
                            return true;
                    }
            } elseif (is_string($context) && ($value == $context)) {
                    return true;
            }
    
            $this->_error(self::NOT_MATCH);
            return false;
    }
    

    And my Form $password = new ZendFormElement_Password(‘passwd’,array( ‘required’ => true, ‘label’ => ‘Password’, ‘size’ => 11 ));

    $confirmation = new ZendFormElement_Password('confirmation',array( 'required' => true, 'label' => 'Re-Password', 'size' => 11 )); //$confirmation->addValidator('PasswordConfirmation',array('passwd'), true);

    Could you help me please…

  8. the validator doesnt take any arguments. Just parse the validator to your elements

    
    // more form code here...
    // $password = new ZendFormElementPassword(.....);
    // $confirm = new Zend
    FormElementPassword(.....);

    $confirmValidator = new MyValidatePasswordConfirmation();
    $password->addValidator($confirmValidator);
    $confirm->addValidator($confirmValidator);

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>