diff options
author | Stefan Kangas <stefankangas@gmail.com> | 2010-12-31 00:09:41 +0100 |
---|---|---|
committer | Stefan Kangas <stefankangas@gmail.com> | 2010-12-31 00:09:41 +0100 |
commit | 999461003a84603f188d69a2281c0aa6071fafeb (patch) | |
tree | 3deeb5f80208e8171591ced9fcd4ef5f7155de24 /lib/Fripost | |
parent | 7a718391b4f8ec8e85902abb55f3511db7eecb59 (diff) |
Automatic password generation for new users
Diffstat (limited to 'lib/Fripost')
-rwxr-xr-x | lib/Fripost/Password.pm | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/Fripost/Password.pm b/lib/Fripost/Password.pm new file mode 100755 index 0000000..eb5ad7e --- /dev/null +++ b/lib/Fripost/Password.pm @@ -0,0 +1,66 @@ +#!/usr/bin/perl + +use 5.010_000; +use warnings; +use strict; + +=head1 NAME + +Password.pm - Generate passwords + +=cut + +our $VERSION = '0.01'; + +use Data::Dumper; +use Digest::MD5; +use Exporter; +use MIME::Base64; + +our @EXPORT = qw/smd5 make_salt/ + +sub smd5 { + my $pw = shift; + my $salt = shift || &make_salt(); + return "{SMD5}" . pad_base64( MIME::Base64::encode( Digest::MD5::md5( $pw . $salt ) . $salt, '' ) ); +} + + +sub make_salt { + my $len = 8 + int( rand(8) ); + my @bytes = (); + for my $i ( 1 .. $len ) { + push( @bytes, rand(255) ); + } + return pack( 'C*', @bytes ); +} + +=head1 AUTHOR + +Stefan Kangas C<< <skangas at skangas.se> >> + +=head1 BUGS + +Please report any bugs to C<< <skangas at skangas.se> >> + +=head1 COPYRIGHT + +Copyright (c) 2010 Dominik Schulz (dominik.schulz@gauner.org). All rights reserved. + +Copyright 2010 Stefan Kangas, all rights reserved. + +=head1 LICENSE + +This program is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +=cut + +1; # End of Password.pm + +__END__ + |