use diagnostics; use strict; use warnings; #sets password ranges my @password; my $password; my $password_length = 0; my $user_length = 0; #seperate arrays for each password type my @chars1 = ('0'..'9'); my @chars2 = ('A'..'Z'); my @chars3 = ('a'..'z'); my @chars4 = ('A'..'Z', 'a'..'z'); my @chars5 = ('A'..'Z', 'a'..'z', '0'..'9'); my @chars6 = ('0'..'9', 'a'..'z', 'A'..'Z', '!','@', '#', '$', '%', '^', '&', '*', '(', ')', '<', '>', '?', '`', '+', '/', '[', '{', ']', '}', '|', '=', '_','~', ',', '.'); #user inputs required length of password print "Enter the required password length. "; chomp($user_length = ); print "\n"; #user selects level of complexity12 print "Select a level of complexity for your password: \n"; print "1. Numeric passcode\t\t\t\t(low level of security) \n"; print "2. Single case alphabetic\t\t\t(low level of security) \n"; print "3. Multi-case alphabetic\t\t\t(low level of security) \n"; print "4. Alphanumeric\t\t\t\t\t(medium level of security) \n"; print "5. Alphanumeric with special characters\t\t(high level of security) \n"; print "Complexity level: "; chomp(my $level = ); print "\n"; if ($level > 1) { while ($user_length < 14) { print "*********************************\n"; print "*\t\tError!\t\t*\n"; print "*********************************\n"; print "\n"; print "Strong password guidelines require a minimum password length of 14 characters."; print "\n"; print "\n"; print "Do you want to generate a password which conforms to strong password guidelines? \n"; chomp (my $guidelines = ); if ($guidelines =~ m/^y/i) { print "Enter a new password length: "; chomp ($user_length = ); } elsif ($guidelines =~ m/^n/i) { goto PW; } } } PW: if ($level == 1) { #mixed case password print "Generating a numeric passcode."; #increments until $user_length is met while ($password_length <= ($user_length-1)) { $password = $chars1[int rand @chars1]; push @password, $password; ++$password_length; } } elsif ( $level == 2) { #single case password print "Select case: \n"; print "1. Upper \n"; print "2. Lower \n"; print "Case: "; chomp(my $case = ); if ($case == 1) { #uppercase password print "Generating an uppercase password."; #increments until $user_length is met while ($password_length <= ($user_length-1)) { $password = $chars2[int rand @chars2]; push @password, $password; ++$password_length; } } else { #lower case password print "Generating a lower case password."; #increments until $user_length is met while ($password_length <= ($user_length-1)) { $password = $chars3[int rand @chars3]; push @password, $password; ++$password_length; } } } elsif ($level == 3) { #mixed case password print "Generating a mixed case password."; #increments until $user_length is met while ($password_length <= ($user_length-1)) { $password = $chars4[int rand @chars4]; push @password, $password; ++$password_length; } } elsif ($level == 4) { #alphanumeric password print "Generating an alphanumeric password."; #increments until $user_length is met while ($password_length <= ($user_length-1)) { $password = $chars5[int rand @chars5]; push @password, $password; ++$password_length; } } else { #alphanumeric password with special characters print "Generating an alphanumeric password with special characters."; #increments until $user_length is met while ($password_length <= ($user_length-1)) { $password = $chars6[int rand @chars6]; push @password, $password; ++$password_length; } } #start export function print "Do you want to export your password to a text file? (y/n) "; chomp(my $export = ); print "\n"; if ($export =~ m/^y/i) { open (FH, '>>password.txt') or die $!; print FH "Your password is: ", @password, "\n"; close FH; } elsif ($export =~ m/^n/i) { print "Your password is: ", @password ,"\n"; } else { print "Enter either y or n to continue. \n" ; #needs to return to top of $export function } print "\n"; print "\n"; print "Your password has been generated. \n";