#!/usr/bin/perl -w # # $Id: md5crypt,v 1.3 2006/03/10 09:02:52 mesrik Exp $ # # BFMI unix_md5_crypt() usage sample and encrypted password generator # use strict; use Crypt::PasswdMD5; use Getopt::Long; use Pod::Usage; my ($passwd,$salt,$crypted); my ($help,$man,$verbose,$vers,$version); $0 =~ s/.*\///o; # weed the path $version = '$Id: md5crypt,v 1.3 2006/03/10 09:02:52 mesrik Exp $'; GetOptions ('help|?' => \$help, 'man' => \$man, 'salt=s' => \$salt, 'verbose!' => \$verbose, 'version' => \$vers ) or pod2usage(2); die "$version\n" if ($vers); pod2usage(1) if $help; pod2usage(-verbose => 2) if $man; pod2usage(1) unless (@ARGV); # initialize srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`); foreach $passwd (@ARGV) { if (defined($salt)) { $crypted = unix_md5_crypt($passwd,$salt); } else { $crypted = unix_md5_crypt($passwd); } if ($verbose) { print $passwd, " "; print $salt," " if ($salt); } print $crypted, ($crypted eq unix_md5_crypt($passwd,$crypted)) ? "\n" : " INTERNAL ERROR: Doublecheck FAILURE!\n"; } __END__ =head1 NAME md5crypt - A utility to produce md5_crypt() passwords. =head1 SYNOPSIS md5crypt [options] { password [ ... ] } =head1 OPTIONS Options: -help brief help message -man more complete documentation -salt='salt' use this explisit salt -verbose a bit more verbose output -version prints version =over 8 =item B<-help> Print a brief help message and exit. =item B<-man> Prints the manual page and exits. =item B<-salt='salt'> Uses given salt when encrypting. =item B<-verbose> Prints a bit more verbose output. =item B<-version> Prints version number and exits. =back =head1 DESCRIPTION B is both MD5 crypt encrypted password generator and a working sample of perl Crypt::PasswdMD5 module usage. It provides compatability FreeBSD, Linux, GRUB etc. commonly used encrypted passwords. More information about MD5 crypt can be found from http://www.usenix.org/events/usenix99/provos/provos_html/node10.html and Perl CPAN Crypt::PasswdMD5 module implementation. =head1 EXAMPLES $ md5crypt snafu $1$RILsmrJ/$jdhGJTsEAi6qhS2DVSluL/ $ md5crypt -verbose -salt=fish foo bar baz foo fish $1$fish$CAo6aPbsIcsaptGgcC5gB0 bar fish $1$fish$BWTWIAvsemgeyfVuMYC39. baz fish $1$fish$JeKDwqEpC2ITv73mP83M31 =head1 CAVEATS Password(s) to be encrypted are with this program given on command line and can thus appear in process listing and/or shell command history -- you have been warned! =head1 MANIFEST This program requires Crypt::PasswdMD5 module from CPAN. =head1 AUTHORS Riku Meskanen =head1 COPYING This program is free softare. It can be distributed by the same license with the Perl itself. =cut # eof