Jozef Kutej > HTML-Widget-Constraint-ComplexPassword-0.01 > HTML::Widget::Constraint::ComplexPassword

Download:
HTML-Widget-Constraint-ComplexPassword-0.01.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

HTML::Widget::Constraint::ComplexPassword - HTML::Widget form constraint that checks if the field is a complex password.

SYNOPSIS ^

        use HTML::Widget;
        
        my $widget = HTML::Widget->new('widget')->method('get')->action('/');
        
        ...
        
        #constraints
        $widget->constraint('Length'          => @columns)
                ->min($HTML::Widget::Constraint::ComplexPassword::MIN_LENGTH)
                ->message('Must be at least '.$HTML::Widget::Constraint::ComplexPassword::MIN_LENGTH.' characters long');
        $widget->constraint('ComplexPassword' => @columns)
                ->message(qq{
                        Must contain at least one upper and one lower case character.
                        Must contain at least one number or a special character -
                        "$HTML::Widget::Constraint::ComplexPassword::SPECIAL_CHARACTERS"
                )};
        
        #or this will be enought but then the error text is too long
        $widget->constraint(ComplexPassword => @columns)
                ->message(qq{
                        Must contain at least $HTML::Widget::Constraint::ComplexPassword::MIN_LENGTH characters and include
                        one upper and one lower case character. Must contain at least one number or a
                        special character - "$HTML::Widget::Constraint::ComplexPassword::SPECIAL_CHARACTERS"
                });

DESCRIPTION ^

A constraint for HTML::Widget to check if the password is complex enought. Password must have at least MIN_LENGTH characters count, one lower case character is required, one upper case character is required and either number or one of SPECIAL_CHARACTERS is needed.

EXPORTS

        our $MIN_LENGTH = 8;
        our $NUMBER_CHARACTERS  = '0123456789';
        our $SPECIAL_CHARACTERS = '~`!@#$%^&*()-_+={}[]\\|:;"\'<>,.?/';

TIPS

If you want to force different password lenght then do:

        use HTML::Widget::Constraint::ComplexPassword;
        $HTML::Widget::Constraint::ComplexPassword::MIN_LENGTH = 10;

or

        $widget->constraint(ComplexPassword => @columns)
                ->min_length(10)
                ->message("bla bla");

If you want just numbers and no other special characters then remove characters from the SPECIAL_CHARACTERS list:

        use HTML::Widget::Constraint::ComplexPassword;
        $HTML::Widget::Constraint::ComplexPassword::SPECIAL_CHARACTERS = '';

You can change both NUMBER_CHARACTERS and SPECIAL_CHARACTERS if you really need to.

TODO ^

It will be nice to have more variants of "complexity". Let's say we can create method ->level($level_type) that will switch between them. For me this default is enought. If you have different demant just drop me an email and i can include it here may be somebody else will reuse.

METHODS ^

min_length()

Set minimum length of password just for current widget.

validate($value)

Perform validation $value validation.

Return true or false if the password is or isn't ok.

SEE ALSO ^

HTML::Widget

AUTHOR ^

Jozef Kutej, <jozef@kutej.net<gt>

COPYRIGHT AND LICENSE ^

Copyright (C) 2007 by Jozef Kutej

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: