How to Generate a Random Password
Developing passwords for a large number of users is a less daunting task if a random password generator is utilized. Passwords can include alphanumerical characters, as well as symbols, and be as lengthy as the developer wishes. Randomly generated passwords are typically issued as a default for new users of an application. A Perl script that generates 7 character passwords constructed of randomized symbols, numbers and letters can be used to generate random passwords.
Instructions
-
-
1
Type the "she-bang" line. This is a line of Perl code that lets the interpreter know that what is being called is a Perl script. This line of code goes at the very top of the script.
#!/usr/bin/perl -
2
Assign character array values. To do this, you will need four different arrays for the four character types in the password. The arrays below are set to numbers from 1 to 9, several character symbols, lowercase letters, and uppercase letters.
@num = (1..9);
@char = ('@','#','$','%','^','&','*','\(','\)');
@alph = ('a'..'z');
@alph_up = ('A'..'Z'); -
-
3
Define the random assignment array. This array combines the elements of the character arrays. There must be 7 of them so some character types will occur with more frequency than others. The decision of what extra character types to include is made by the developer.
@lets = (@alph,@alph_up,@num,@num,@char,@alph,@num1); -
4
Assign password variables. In this snippet of code, each character of the password is assigned a randomized value through the "int rand" command which randomizes the items in each array.
$rand_let1 = $lets[int rand @lets];
$rand_let2 = $lets[int rand @lets];
$rand_let3 = $lets[int rand @lets];
$rand_let4 = $lets[int rand @lets];
$rand_let5 = $lets[int rand @lets];
$rand_let6 = $lets[int rand @lets];
$rand_let7 = $lets[int rand @lets]; -
5
Program the output. In this program, the output is printed to the Windows shell as an individual password. The following code allows the password to be assembled.
print "$rand_let1"."$rand_let2"."$rand_let3"."$rand_let4"."$rand_let5".
"$rand_let6"."$rand_let7\n";
Save the code as "pass_gen.pl." - 6
-
1
Tips & Warnings
Make the password as short or as lengthy as you see fit. If you would like to save the passwords you generate to a list in a text file, type open "(PASS,">>pass.txt");" under the she bang line and type "print PASS "$rand_let1"."$rand_let2"."$rand_let3"."$rand_let4"."$rand_let5"."$rand_let6"."$rand_let7\n";" under the first print command. The "pass.txt" text file will get generated and saved automatically in the same directory as your program.
References
- Photo Credit Personal Collection