| 1 | package Authen::Simple::Password; | ||||||||||
| 2 | |||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 6 | ▶ | use Crypt::PasswdMD5 qw[]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 6 | ▶ | use Digest::MD5 qw[]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 6 | ▶ | use Digest::SHA qw[]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 6 | ▶ | use MIME::Base64 qw[]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 16 | ▶ | sub check { | ||||||||
|
Subroutine
check: called CC=25 SCAR=40.8
Pod
documented
| |||||||||||
| 12 | 16 | my ( $class, $password, $encrypted ) = @_; | |||||||||
| 13 | |||||||||||
| 14 | # Plain | ||||||||||
| 15 | 16 | ▶ | return 1 if $password eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | # L S | ||||||||||
| 18 | # Des 13 2 | ||||||||||
| 19 | # Extended DES 20 9 | ||||||||||
| 20 | # $1$ MD5 34 12 | ||||||||||
| 21 | # $2$ Blowfish 34 16 | ||||||||||
| 22 | # $3$ NT-Hash ? ? | ||||||||||
| 23 | |||||||||||
| 24 | # Crypt | ||||||||||
| 25 | 15 | ▶ | return 1 if crypt( $password, $encrypted ) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | # Crypt Modular Format | ||||||||||
| 28 | 13 | ▶ | if ( $encrypted =~ /^\$(\w+)\$/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 1 | ▶ | return 1 if $class->_check_modular( $password, $encrypted, lc($1) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | # LDAP Format | ||||||||||
| 33 | 12 | ▶ | if ( $encrypted =~ /^\{(\w+)\}/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 6 | ▶ | return 1 if $class->_check_ldap( $password, $encrypted, lc($1) ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | # MD5 | ||||||||||
| 38 | 6 | ▶ | if ( length($encrypted) == 16 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 1 | ▶ | return 1 if Digest::MD5::md5($password) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 5 | ▶ | if ( length($encrypted) == 22 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 1 | ▶ | return 1 if Digest::MD5::md5_base64($password) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 4 | ▶ | if ( length($encrypted) == 32 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 1 | ▶ | return 1 if Digest::MD5::md5_hex($password) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | # SHA-1 | ||||||||||
| 51 | 3 | ▶ | if ( length($encrypted) == 20 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 1 | ▶ | return 1 if Digest::SHA::sha1($password) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 2 | ▶ | if ( length($encrypted) == 27 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 1 | ▶ | return 1 if Digest::SHA::sha1_base64($password) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 1 | ▶ | if ( length($encrypted) == 40 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 1 | ▶ | return 1 if Digest::SHA::sha1_hex($password) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | # SHA-2 256 | ||||||||||
| 64 | 0 | ▶ | if ( length($encrypted) == 32 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 0 | ▶ | return 1 if Digest::SHA::sha256($password) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 0 | ▶ | if ( length($encrypted) == 43 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | ▶ | return 1 if Digest::SHA::sha256_base64($password) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 0 | ▶ | if ( length($encrypted) == 64 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | ▶ | return 1 if Digest::SHA::sha256_hex($password) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | return 0; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 6 | ▶ | sub _check_ldap { | ||||||||
|
Subroutine
_check_ldap: called CC=13 SCAR=26.3
| |||||||||||
| 80 | 6 | my ( $class, $password, $encrypted, $scheme ) = @_; | |||||||||
| 81 | |||||||||||
| 82 | 6 | ▶ | if ( $scheme eq 'cleartext' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 1 | my $hash = substr( $encrypted, 11 ); | |||||||||
| 84 | 1 | ▶ | return 1 if $password eq $hash; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 5 | ▶ | if ( $scheme eq 'crypt' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 1 | my $hash = substr( $encrypted, 7 ); | |||||||||
| 89 | 1 | ▶ | return 1 if crypt( $password, $hash ) eq $hash; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 4 | ▶ | if ( $scheme eq 'md5' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 1 | my $hash = MIME::Base64::decode( substr( $encrypted, 5 ) ); | |||||||||
| 94 | 1 | ▶ | return 1 if Digest::MD5::md5($password) eq $hash; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 3 | ▶ | if ( $scheme eq 'smd5' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 1 | my $hash = MIME::Base64::decode( substr( $encrypted, 6 ) ); | |||||||||
| 99 | 1 | my $salt = substr( $hash, 16 ); | |||||||||
| 100 | 1 | ▶ | return 1 if Digest::MD5::md5( $password, $salt ) . $salt eq $hash; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | 2 | ▶ | if ( $scheme eq 'sha' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | 1 | my $hash = MIME::Base64::decode( substr( $encrypted, 5 ) ); | |||||||||
| 105 | 1 | ▶ | return 1 if Digest::SHA::sha1($password) eq $hash; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 1 | ▶ | if ( $scheme eq 'ssha' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 1 | my $hash = MIME::Base64::decode( substr( $encrypted, 6 ) ); | |||||||||
| 110 | 1 | my $salt = substr( $hash, 20 ); | |||||||||
| 111 | 1 | ▶ | return 1 if Digest::SHA::sha1( $password, $salt ) . $salt eq $hash; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | 0 | return 0; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 1 | ▶ | sub _check_modular { | ||||||||
|
Subroutine
_check_modular: called CC=5 SCAR=20.9
| |||||||||||
| 118 | 1 | my ( $class, $password, $encrypted, $format ) = @_; | |||||||||
| 119 | |||||||||||
| 120 | 1 | ▶ | if ( $format eq '1' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 121 | 0 | ▶ | return 1 if Crypt::PasswdMD5::unix_md5_crypt( $password, $encrypted ) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 1 | ▶ | if ( $format eq 'apr1' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 125 | 1 | ▶ | return 1 if Crypt::PasswdMD5::apache_md5_crypt( $password, $encrypted ) eq $encrypted; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | 0 | return 0; | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | 6 | 1; | |||||||||
| 132 | |||||||||||
| 133 | __END__ | ||||||||||