M
Mark Drummond
I have a chunk of code that generates a random password form a specified
set of characters. Once the password is generated I want to test it for
certain characteristics and if it does not meet those characteristics
then I want to toss it and start again. What I am working with looks
something like (not necessarily correct code below!):
sub newpass {
my $pass
my $badpass = 1;
my $rand;
my $passlen = $_[0];
$passlen = 8 if !$passlen;
my @chars = qw/ a b c ...
A B C ...
0 1 2 ... /;
while ($badpass == 1) {
$pass = "";
for (my $i=0; $i < $passlen; $i++) {
$rand = int(rand $#chars+1);
$pass .= $chars[$rand];
}
#
# INSERT PASSWORD TESTS HERE
#
$badpass = 0;
}
return $pass
}
I wanted to do something like the following for my tests:
# test for at least one lowercase char
next if $pass =~ /[[:lower:]]/;
# test for at least one uppercase char
next if $pass =~ /[[:upper:]]/;
# test for at least one digit
next if $pass =~ /[[:digit:]]/;
But my program just spins in an infinite loop. So clearly I have no idea
what I am doing!!
Any tips?!
Mark
set of characters. Once the password is generated I want to test it for
certain characteristics and if it does not meet those characteristics
then I want to toss it and start again. What I am working with looks
something like (not necessarily correct code below!):
sub newpass {
my $pass
my $badpass = 1;
my $rand;
my $passlen = $_[0];
$passlen = 8 if !$passlen;
my @chars = qw/ a b c ...
A B C ...
0 1 2 ... /;
while ($badpass == 1) {
$pass = "";
for (my $i=0; $i < $passlen; $i++) {
$rand = int(rand $#chars+1);
$pass .= $chars[$rand];
}
#
# INSERT PASSWORD TESTS HERE
#
$badpass = 0;
}
return $pass
}
I wanted to do something like the following for my tests:
# test for at least one lowercase char
next if $pass =~ /[[:lower:]]/;
# test for at least one uppercase char
next if $pass =~ /[[:upper:]]/;
# test for at least one digit
next if $pass =~ /[[:digit:]]/;
But my program just spins in an infinite loop. So clearly I have no idea
what I am doing!!
Any tips?!
Mark