A collegue of mine was complaining to me that he had to create accounts for 750 people on a mix of Solaris and Linux systems where he works. And he had to do it within a couple of days.

Given that he had the names and account ids in a comma delimited file all he needed was to create the accounts and send the passwords to the account owners. But where in the world was he coming up with all those passwords?

Part of the issue was on one store for account information they use SALT encryption and on the other they use MD5 passwords.

This is by no means the only way to do it but it was something I whipped up in less than 20 minutes to solve the problem. Hope this may be of some service to the next person.

A lot of extra code was left out of this for clarity sake. Some of the logic I left out was:

A couple of caveats

#!/usr/bin/perl -w ###################################################################### +## use strict; use Tie::File; use Fcntl 'O_RDONLY'; use Digest::MD5 qw(md5_hex); use Data::Dumper; print Dumper(random_password()),"\n" foreach 0..4; exit(0); sub random_password { my @punct= qw/ ; : + = % $ ! . /; my $retval={}; my $word1 = select_a_word(); my $word2 = select_a_word(); my $plain_text= $word1 . $punct[rand($#punct)+1] . $word2; $retval->{plain_text}=$plain_text; $retval->{md5_hash} = md5_hex($plain_text); $retval->{crypt} = crypt($plain_text,pass_the_salt()); return $retval; } sub pass_the_salt { my @salt_lick = ( 'a'..'z' ); return $salt_lick[rand($#salt_lick)+1] . $salt_lick[rand($#salt_li +ck)+1]; } sub select_a_word { my @words=(); tie @words,"Tie::File","/usr/share/dict/linux.words",mode=>O_RDONL +Y or die $!; my $word = $words[rand($#words)]; $word =~ tr /A-Z/a-z/; untie @words; if (length($word) > 6 ) { return select_a_word(); } eles { return $word; } }

In reply to Creating random passwords for users. by blue_cowdawg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.