From 999461003a84603f188d69a2281c0aa6071fafeb Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Fri, 31 Dec 2010 00:09:41 +0100 Subject: Automatic password generation for new users --- lib/Fripost/Password.pm | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 lib/Fripost/Password.pm (limited to 'lib/Fripost') 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<< >> + +=head1 BUGS + +Please report any bugs to C<< >> + +=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__ + -- cgit v1.2.3