| 1 | package HTML::FormHandler::Field::Password; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: password field | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | $HTML::FormHandler::Field::Password::VERSION = '0.410000'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use HTML::FormHandler::Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | extends 'HTML::FormHandler::Field::Text'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | has '+widget' => ( default => 'Password' ); | |||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | has '+password' => ( default => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | has 'ne_username' => ( isa => 'Str', is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | has '+type_attr' => ( default => 'password' ); | |||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | has '+html5_type_attr' => ( default => 'password' ); | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | our $class_messages = { | |||||||||||||||||||||||||||||||||||||||||
| 15 | 'required' => 'Please enter a password in this field', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 'password_ne_username' => 'Password must not match [_1]', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | sub get_class_messages { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_class_messages: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | my $messages = { | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | %{ $self->next::method }, | |||||||||||||||||||||||||||||||||||||||||
| 23 | %$class_messages, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | $messages->{required} = $self->required_message | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | if $self->required_message; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | return $messages; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | after 'validate_field' => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 10 | ▶ | if ( !$self->required && !( defined( $self->value ) && length( $self->value ) ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->required || defined $self->value && length $self->value
defined $self->value and length $self->value
MC/DC66%2/3
$self->required || defined $self->value && length $self->value
$self->required
defined $self->value
length $self->value
Truth table75%3/4
A || B and C
A= $self->requiredB= defined $self->valueC= length $self->value
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | $self->noupdate(1); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | $self->clear_errors; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | sub validate { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 8 | $self->noupdate(0); | |||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | ▶ | return unless $self->next::method; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | my $value = $self->value; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 7 | ▶ | if ( $self->form && $self->ne_username ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->form and $self->ne_username
MC/DC50%1/2
$self->form and $self->ne_username
$self->form
$self->ne_username
Truth table66%2/3
A and B
A= $self->formB= $self->ne_username
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | my $username = $self->form->get_param( $self->ne_username ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | return $self->add_error( $self->get_message('password_ne_username'), $self->ne_username ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$username and $username eq $value
MC/DC50%1/2
$username and $username eq $value
$username
$username eq $value
Truth table66%2/3
A and B
A= $usernameB= $username eq $value
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | if $username && $username eq $value; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | HTML::FormHandler::Field::Password - password field | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | version 0.410000 | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | The password field has a default minimum length of 6, which can be | ||||||||||||||||||||||||||||||||||||||||||
| 76 | easily changed: | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | has_field 'password' => ( type => 'Password', minlength => 7 ); | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | It does not come with additional default checks, since password | ||||||||||||||||||||||||||||||||||||||||||
| 81 | requirements vary so widely. There are a few constraints in the | ||||||||||||||||||||||||||||||||||||||||||
| 82 | L<HTML::FormHandler::Types> modules which could be used with this | ||||||||||||||||||||||||||||||||||||||||||
| 83 | field: NoSpaces, WordChars, NotAllDigits. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | These constraints can be used in the field definitions 'apply': | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | use HTML::FormHandler::Types ('NoSpaces', 'WordChars', 'NotAllDigits' ); | ||||||||||||||||||||||||||||||||||||||||||
| 87 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 88 | has_field 'password' => ( type => 'Password', | ||||||||||||||||||||||||||||||||||||||||||
| 89 | apply => [ NoSpaces, WordChars, NotAllDigits ], | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | You can add your own constraints in addition, of course. | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | If a password field is not required, then the field will be marked 'noupdate', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | to prevent a null from being saved into the database. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =head2 ne_username | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | Set this attribute to the name of your username field (default 'username') | ||||||||||||||||||||||||||||||||||||||||||
| 100 | if you want to check that the password is not the same as the username. | ||||||||||||||||||||||||||||||||||||||||||
| 101 | Does not check by default. | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | FormHandler Contributors - see HTML::FormHandler | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 112 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||||||||||||||||