Gossamer Forum
Home : General : Perl Programming :

Password Checker CGI-Perl code

Quote Reply
Password Checker CGI-Perl code
Hi:

I'm looking for some code to check submitted passwords to ensure that passwords:

1. are a minimum of 7 charcters.
2. contain both letters and numbers - at least one of each. And contains no other characters.
3. contain both upper and lower case characters - at least one of each.

This would augment my current check to ensure that Usernames and Passwords are unique. Any help would be greatly appreciated.

Dan Smile
Quote Reply
Re: Password Checker CGI-Perl code In reply to
How about:

Code:
sub good_pass {
# -----------------------------------------
my $input = shift;

# Must be 7 characters or quit.
len ($input) < 7 and return undef;
# Must contain a lowercase, an upper case
# and a number or quit.
($input =~ /[a-z]/ and ($input =~ /[0-9]/) and ($input = /[A-Z]/)
or return undef;
# Must contain only upper, lower and numbers.
($input =~ /^[A-Za-z0-9]+$/) or return undef;
return $input;
}

Then you could do: if (&good_password($pass)) { ... } else { die "Bad pass!"; }

Hope that helps,

Alex
Quote Reply
Re: Password Checker CGI-Perl code In reply to
Beautiful! Thanks Alex!

Dan Smile