Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: Removing similar characters

by rspishock (Monk)
on Sep 03, 2011 at 11:07 UTC ( #923978=note: print w/replies, xml ) Need Help??

in reply to Re: Removing similar characters
in thread Removing similar characters

See below for the code. I have 6 arrays set up to handle the various types of passwords that the user could request. Once the user inputs the type of password and the password length, I'm using the rand function to generate the password and then either output it to the user directly, or output it to a file. The script also checks the length of the password and warns them if it is below 14 characters, suggesting that longer passwords are more secure. </P.

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 = <STDIN>); 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 secur +ity) \n"; print "Complexity level: "; chomp(my $level = <STDIN>); 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 l +ength of 14 characters."; print "\n"; print "\n"; print "Do you want to generate a password which conforms to st +rong password guidelines? \n"; chomp (my $guidelines = <STDIN>); if ($guidelines =~ m/^y/i) { print "Enter a new password length: "; chomp ($user_length = <STDIN>); } 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 = <STDIN>); 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 = <STDIN>); 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";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://923978]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2016-12-11 06:22 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (168 votes). Check out past polls.