Nitesi/Account/Password.pm

filter: Statementstmt 100% 29 / 29 Branchbran 100% 2 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 91.4% 43 / 47 CC 3 SCAR 3.6
CC
3
Cov
94%
make_password
2.1
password
2.0
BEGIN
1.0
CRAP 1.4
« Nitesi/Transaction.pm ↑ Summary Nitesi.pm »
1 package Nitesi::Account::Password;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Crypt::Password 0.23 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Data::SimplePassword;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Nitesi::Account::Password - Password class for Nitesi Shop Machine
14  
15 =head1 DESCRIPTION
16  
17 Allows to create random passwords, password hashes from cleartext
18 passwords and password checks.
19  
20 =head1 METHODS
21  
22 =head2 check
23  
24 Checks password retrieved from user against the password hash.
25  
26 $crypt->check($hash_from_database, $user_input);
27  
28 =cut
29  
30 4 ▶sub check {
Subroutine check: called CC=1 SCAR=0.0
Pod documented
31 4 my ($self, $hash, $password) = @_;
32  
33 4 Crypt::Password::check_password($hash, $password);
34 }
35  
36 =head2 password
37  
38 Creates password hash from plain text password.
39  
40 $crypt->password('nevairbe');
41  
42 Use specific algorithm (default is sha512):
43  
44 $crypt->password('nevairbe', 'md5');
45  
46 =cut
47  
48 2 ▶sub password {
Subroutine password: called CC=2 SCAR=6.9
Pod documented
49 2 my ($self, $password, $algorithm, $salt);
50  
51 2 $self = shift;
52 2 $password = shift;
53  
54 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 1 2
55 # got algorithm
56 1 $algorithm = shift;
57 }
58 else {
59 1 $algorithm = 'sha512';
60 }
61  
62 2 $password = Crypt::Password::password($password, undef, $algorithm);
63  
64 2 return $password;
65 }
66  
67 =head2 make_password
68  
69 Creates random password.
70  
71  
72 B<Example>
73  
74 $crypt->make_password();
75  
76 =cut
77  
78 1 ▶sub make_password {
Subroutine make_password: called CC=2 SCAR=7.6
Pod documented
79 1 my $self = shift;
80  
81 1 ▶ $self->{generator} ||= Data::SimplePassword->new;
Condition33%1/3
$self->{"generator"} ||= "Data::SimplePassword"->new
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"generator"} ||= "Data::SimplePassword"->new
$self->{"generator"} "Data::SimplePassword"->new
Truth table33%1/3
A ||= B
A= $self->{"generator"}B= "Data::SimplePassword"->new
ABresult
1X1
011
000
82 1 $self->{generator}->make_password;
83 }
84  
85 =head1 AUTHOR
86  
87 Stefan Hornburg (Racke), <racke@linuxia.de>
88  
89 =head1 LICENSE AND COPYRIGHT
90  
91 Copyright 2011-2013 Stefan Hornburg (Racke) <racke@linuxia.de>.
92  
93 This program is free software; you can redistribute it and/or modify it
94 under the terms of either: the GNU General Public License as published
95 by the Free Software Foundation; or the Artistic License.
96  
97 See http://dev.perl.org/licenses/ for more information.
98  
99 =cut
100  
101  
102 2 1;
« Nitesi/Transaction.pm ↑ Summary Nitesi.pm »