| 1 | package POE::Component::Server::IRC::Common; | ||||||||||||||||||||||||||||
| 2 | BEGIN { | ||||||||||||||||||||||||||||
| 3 | 21 | ▶ | $POE::Component::Server::IRC::Common::AUTHORITY = 'cpan:HINRIK'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | { | ||||||||||||||||||||||||||||
| 6 | 21 | $POE::Component::Server::IRC::Common::VERSION = '1.54'; | |||||||||||||||||||||||||||
| 7 | } | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 21 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 21 | ▶ | use Crypt::PasswdMD5; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 21 | require Exporter; | |||||||||||||||||||||||||||
| 14 | 21 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 21 | our @EXPORT_OK = qw(mkpasswd chkpasswd); | |||||||||||||||||||||||||||
| 16 | 21 | our %EXPORT_TAGS = ( ALL => [@EXPORT_OK] ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub mkpasswd { | ||||||||||||||||||||||||||||
| 19 | 3 | ▶ | my ($plain, %opts) = @_; | ||||||||||||||||||||||||||
|
Subroutine
mkpasswd: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | return if !defined $plain || !length $plain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $plain and length $plain
MC/DC0%0/2
defined $plain and length $plain
defined $plain
length $plain
Truth table33%1/3
A and B
A= defined $plainB= length $plain
| |||||||||||||||||||||||||||||
| 21 | 3 | $opts{lc $_} = delete $opts{$_} for keys %opts; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | return unix_md5_crypt($plain) if $opts{md5}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | return apache_md5_crypt($plain) if $opts{apache}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 1 | my $salt = join '', ('.','/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]; | |||||||||||||||||||||||||||
| 26 | 1 | return crypt($plain, $salt); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub chkpasswd { | ||||||||||||||||||||||||||||
| 30 | 6 | ▶ | my ($pass, $chk) = @_; | ||||||||||||||||||||||||||
|
Subroutine
chkpasswd: called CC=11 SCAR=25.5
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 6 | ▶ | return if !defined $pass || !length $pass; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $pass and length $pass
MC/DC0%0/2
defined $pass and length $pass
defined $pass
length $pass
Truth table33%1/3
A and B
A= defined $passB= length $pass
| |||||||||||||||||||||||||||||
| 32 | 6 | ▶ | return if !defined $chk || !length $chk; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $chk and length $chk
MC/DC0%0/2
defined $chk and length $chk
defined $chk
length $chk
Truth table33%1/3
A and B
A= defined $chkB= length $chk
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 6 | my $md5 = '$1$'; my $apr = '$apr1$'; | |||||||||||||||||||||||||||
| 35 | 6 | ▶ | if (index($chk,$apr) == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 36 | 1 | my $salt = $chk; | |||||||||||||||||||||||||||
| 37 | 1 | $salt =~ s/^\Q$apr//; | |||||||||||||||||||||||||||
| 38 | 1 | $salt =~ s/^(.*)\$/$1/; | |||||||||||||||||||||||||||
| 39 | 1 | $salt = substr( $salt, 0, 8 ); | |||||||||||||||||||||||||||
| 40 | 1 | ▶ | return 1 if apache_md5_crypt($pass, $salt) eq $chk; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | elsif ( index($chk,$md5) == 0 ) { | ||||||||||||||||||||||||||||
| 43 | 1 | my $salt = $chk; | |||||||||||||||||||||||||||
| 44 | 1 | $salt =~ s/^\Q$md5//; | |||||||||||||||||||||||||||
| 45 | 1 | $salt =~ s/^(.*)\$/$1/; | |||||||||||||||||||||||||||
| 46 | 1 | $salt = substr( $salt, 0, 8 ); | |||||||||||||||||||||||||||
| 47 | 1 | ▶ | return 1 if unix_md5_crypt($pass, $salt) eq $chk; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 4 | ▶ | return 1 if crypt( $pass, $chk ) eq $chk; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 3 | ▶ | return 1 if $pass eq $chk; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | return; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 21 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =encoding utf8 | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 NAME | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | POE::Component::Server::IRC::Common - provides a set of common functions for the POE::Component::Server::IRC suite. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | use strict; | ||||||||||||||||||||||||||||
| 66 | use warnings; | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | use POE::Component::Server::IRC::Common qw( :ALL ); | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | my $passwd = mkpasswd( 'moocow' ); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | POE::Component::IRC::Common provides a set of common functions for the | ||||||||||||||||||||||||||||
| 76 | L<POE::Component::Server::IRC|POE::Component::Server::IRC> suite. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head2 C<mkpasswd> | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Takes one mandatory argument a plain string to 'encrypt'. If no further | ||||||||||||||||||||||||||||
| 83 | options are specified it uses C<crypt> to generate the password. Specifying | ||||||||||||||||||||||||||||
| 84 | 'md5' option uses L<Crypt::PasswdMD5|Crypt::PasswdMD5>'s C<unix_md5_crypt> | ||||||||||||||||||||||||||||
| 85 | function to generate the password. Specifying 'apache' uses | ||||||||||||||||||||||||||||
| 86 | Crypt::PasswdMD5 C<apache_md5_crypt> function to generate the password. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | my $passwd = mkpasswd( 'moocow' ); # vanilla crypt() | ||||||||||||||||||||||||||||
| 89 | my $passwd = mkpasswd( 'moocow', md5 => 1 ) # unix_md5_crypt() | ||||||||||||||||||||||||||||
| 90 | my $passwd = mkpasswd( 'moocow', apache => 1 ) # apache_md5_crypt() | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head2 C<chkpasswd> | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Takes two mandatory arguments, a password string and something to check that | ||||||||||||||||||||||||||||
| 95 | password against. The function first tries md5 comparisons (UNIX and Apache), | ||||||||||||||||||||||||||||
| 96 | then C<crypt> and finally plain-text password check. | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Chris 'BinGOs' Williams | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Copyright E<copy> Chris Williams | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | This module may be used, modified, and distributed under the same terms as | ||||||||||||||||||||||||||||
| 107 | Perl itself. Please see the license that came with your Perl distribution | ||||||||||||||||||||||||||||
| 108 | for details. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | L<POE::Component::Server::IRC|POE::Component::Server::IRC> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||