views:

768

answers:

4

We have to automatically import a large list of users with some data into a running system. For an initial password I want to update the list (csv format at the moment) with a random alphanumeric key (8 digits).

When inserting it with a special routine (which needs a csv file), the password (in this case the alphanumeric key) is stored as a md5 hash.

i.e. I generate a random alphanumeric key:

H2A5D39A -> MD5: 1642fccf791f15d137cf31282af79752

This way I want to create a list where authenticated users can ask me for their initial password (the alphanumeric key).

Do you have a better idea for a "secret" initial password?

How would you create the alphanumeric key in Perl?

P.S.: The "running system", not programmed by us, just allowes alphanumeric passwords (no special chars,...)

+9  A: 

How would you create the alphanumeric key in Perl?

join'', map +(0..9,'a'..'z','A'..'Z')[rand(10+26*2)], 1..8

Anonymous
+1 nice one liner
dfa
Watch out for similarities between I,l, and 1 and 0 and O. Easily handled by assigning your char list to an array, and then doing: join '', map $chars[rand @chars], 1..8;
daotoad
+5  A: 

I would probably use pwgen. It is great as it allows easy customization, and has the switch not to use ambiguous characters (think: I, l, 1, O, 0).

for example:

=> pwgen -c -n -B 8 50
shuFak9o peiCh3Oo ohPieng9 Vohh7zuu os3Theep aeV9nuo9 aexeik4B aeChoh9s
uth3eePu baePhu3o aiS3pahn iPie4itu We9zuphi xie3Chi3 yeiRoo7c fai3ITai
aCh9ohco Echuab7v Fu9ahCho Aevae4no Peethai9 AiJio3Pa aeNge9Fo baePh7Uy
Nai7shei eeMoh9en Zeibai4n eGe7yuch Jaek7nai aeZah7sh Chei4ua4 shoo9oG9
iu7Wohho aep7De4U Fong9fo3 AhneeP7U oxae7Yoh ahF4eim3 fahm9Aiw naoNg4ie
Chie4xua jix3Uvot aChei7ai diey4Shi Yur7ee4j eeJeo9ee Bou3ahmu kaeb4Cah
Eh4Eemae oD4phoo9
depesz
+1  A: 

Anonymous's answer is very good, but, if you need a random string that conforms to some rules (such as at least one uppercase, one lowercase, and one number), you may want to look into String::Random.

Chas. Owens
A: 

Another module to consider is Data::Random

mpeters