From c1bf5f074f8c6c079445d836dcdaf7b9bbc911ea Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Fri, 31 Dec 2010 00:36:47 +0100 Subject: Fix password generation, add missing subroutine --- fripost-mkpass.pl | 1 - lib/Fripost/Password.pm | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fripost-mkpass.pl b/fripost-mkpass.pl index 3b0c9f7..fba5079 100755 --- a/fripost-mkpass.pl +++ b/fripost-mkpass.pl @@ -24,7 +24,6 @@ my $password = mkpasswd( -minnum => 5, -minspecial => 3 ); -$user{password} = smd5($password); # Show the information that will be inserted say "Generated password: $password"; diff --git a/lib/Fripost/Password.pm b/lib/Fripost/Password.pm index eb5ad7e..0205799 100755 --- a/lib/Fripost/Password.pm +++ b/lib/Fripost/Password.pm @@ -17,7 +17,7 @@ use Digest::MD5; use Exporter; use MIME::Base64; -our @EXPORT = qw/smd5 make_salt/ +our @EXPORT = qw/smd5 make_salt/; sub smd5 { my $pw = shift; @@ -25,7 +25,6 @@ sub smd5 { return "{SMD5}" . pad_base64( MIME::Base64::encode( Digest::MD5::md5( $pw . $salt ) . $salt, '' ) ); } - sub make_salt { my $len = 8 + int( rand(8) ); my @bytes = (); @@ -35,6 +34,14 @@ sub make_salt { return pack( 'C*', @bytes ); } +sub pad_base64 { + my $b64_digest = shift; + while ( length($b64_digest) % 4 ) { + $b64_digest .= '='; + } + return $b64_digest; +} + =head1 AUTHOR Stefan Kangas C<< >> -- cgit v1.2.3