(Answer) (Category) OpenLDAP Faq-O-Matic : (Category) OpenLDAP Software FAQ : (Category) Configuration : (Category) SLAPD Configuration : (Category) Passwords : (Answer) A script to generate MD5, SHA, and CRYPT variants of a password
Borrowing liberally from the previous answers, and doing a bit of hacking, 
I produced the following Perl script (frontended by a Korn shell script) 
to generate the CRYPT, MD5, and SHA forms of one or more strings.

First, the shell wrapper:

===== begin hashit.sh =====
#!/usr/bin/ksh
for x in $@
        do
        hashit.pl ${x}
        done
====== end  hashit.sh =====

This allows me to input multiple strings.

Now, for the Perl script:

===== begin  hashit.pl =====

#!/usr/bin/perl -I /usr/lib/perl5/site_perl/5.005/i386-linux

# Perl code to create and print SHA1 and MD5 hashes of passwords
# shamelessly stolen from the openLDAP Faq-O-Matic
# written 19-Jul-01 by Ed Truitt
# Updated 12-Oct-01 to include a {crypt} version of the password

$theGoodWord = $ARGV[0];
chomp($theGoodWord);

# First, print the clear text version

print "\n" ;
print "The Good Word is ==> $theGoodWord \n " ;
print "\n" ;

# Now generate and print the SHA1 hash

use Digest::SHA1;
use MIME::Base64;
$ctx = Digest::SHA1->new;
$ctx->add($theGoodWord);
$hashedSHAPasswd = '{SHA}' . encode_base64($ctx->digest,'');
print 'userPassword: ' .  $hashedSHAPasswd . "\n";


# Now generate and print the MD5 hash

use Digest::MD5;
use MIME::Base64;
$ctx = Digest::MD5->new;
$ctx->add($theGoodWord);
$hashedMD5Passwd = '{MD5}' . encode_base64($ctx->digest,'');
print 'userPassword: ' .  $hashedMD5Passwd . "\n";


# Now generate and print the CRYPT version

# first we need to generate the salt

@chars = ("A" .. "Z", "a" .. "z", 0 .. 9, qw(. /) );
$salt = join("", @chars[ map { rand @chars} ( 1 .. 4) ]);

# now to generate the password itself

$cryptPasswd = '{crypt}' . crypt($theGoodWord,$salt);
print 'userPassword: ' .  $cryptPasswd . "\n";
print "\n";

===== end of hashit.pl =====

So, once you have these two files created and the proper permissions 
set (chmod +x), you can run them and create passwords as follows:

> hashit.sh helloworld iamfine good4you?

The Good Word is ==> helloworld

userPassword: {SHA}at+xg6SiyUovktq1redipHiJpaE=
userPassword: {MD5}/F4DjTilcDIIVEHn/nAQsA==
userPassword: {crypt}0pnSC65.QhkYc


The Good Word is ==> iamfine

userPassword: {SHA}8+/DbNY5nCOkV2HQ31B6Nr8DC9Y=
userPassword: {MD5}w2Je+JehACIdaK7fgQQGNA==
userPassword: {crypt}/74LUdpOYCTv2


The Good Word is ==> good4you?

userPassword: {SHA}OAPD3WRiNcowtGILlMmgqW7EbQ8=
userPassword: {MD5}f0llSo0iGQ1hq3E1L5RP1Q==
userPassword: {crypt}kiV2nC14UfcK6

I have used this to generate multiple passwords (for example, when creating 
LDIFs to bulk load entries), where I want different passwords, but don't want 
to enter them in plain text (UGH!).  The use of "userPassword" preceding allows 
for a simple cut/paste into the LDIF.
ed.truitt@etee2k.net
[Append to This Answer]
Previous: (Answer) What are {CRYPT} passwords and how do I generate them?
Next: (Answer) How do I specify what type of password are stored?
This document is: http://www.openldap.org/faq/index.cgi?file=629
[Search] [Appearance]
This is a Faq-O-Matic 2.721.test.
© Copyright 1998-2013, OpenLDAP Foundation, info@OpenLDAP.org