- 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
Execute the program. In the Windows command prompt, go to the directory where the gen_pass.pl file is saved. Once in the directory, type the following to run the program.
"perl gen_pass.pl"
You should get a randomized 7 character password as output.
previous post