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


HTML-Widget-Constraint-ComplexPassword documentation  | view source Contained in the HTML-Widget-Constraint-ComplexPassword distribution.

Index


NAME

Top

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

SYNOPSIS

Top

	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

Top

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

Top

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

Top

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

Top

HTML::Widget

AUTHOR

Top

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

COPYRIGHT AND LICENSE

Top


HTML-Widget-Constraint-ComplexPassword documentation  | view source Contained in the HTML-Widget-Constraint-ComplexPassword distribution.