Perl password random generator

This example shows how to generate a random password:

@arr = (A..Z);

print $/;
for(1..8){
print $arr[rand($#arr)];
}
print $/;

Prints this result:

CACUHWHK
KVCONNCL

 

For better Random numbers we use Math::Random:

use Math::Random;
@arr = (A..Z);
print $/;
for(1..8){
print random_permutation(@arr);
}
print $/;

Our result looks like :

ZUROWXGEITNPJBYSFH8AMKLCDQVIQFU8SLJDEHBKPYZWGATONRXVCMTBCDQXGKOPIAMRFEYSHW8LVZNUJPCXRGSAYVOLNMIKBEFTUQJW8DHZNEGB8AMYPRLQVUWTFZKSXHCOIJDXFIVBED8PNRUTMHJCOAYQSLGWKZVQBHNMA8CIWYFTOJLEZGDXPUKSRDFWOAMZVIQUCBEJSRKYP8LXTNHG

Thats much better.

 

For real use use more digits and better a array like this:

@arr = (A..Z,a..z,0..9);

Leave a Reply

Your email address will not be published.

3 × five =