Check password with Perl

This little Perl-Script checks if we use a password longer than 9 characters, 2 lower-case digits, 2 upper-case digits, 2 numbers and 2 special chars.

use strict;

print checkPW("password").$/;
print checkPW("passwordt").$/;
print checkPW("PaSswordt").$/;
print checkPW("2PaSsword5").$/;
print checkPW("2PaSs/word5@").$/;

sub checkPW {
return("length must longer than 9!") unless(length $_[0] >= 9);
return("no upper-case!") unless($_[0] =~ /^.*[A-Z].*[A-Z].*$/o);
return("no lower-case!") unless($_[0] =~ /^.*[a-z].*[a-z].*$/o);
return("no numbers!") unless($_[0] =~ /^.*[0-9].*[0-9].*$/o);
return("no special chars!") unless($_[0] =~ /.*[^A-Za-z0-9n].*[^A-Za-z0-9n].*/o);
return("OK");
}

And our result looks like:

length must longer than 9! 
no upper-case!
no numbers! 
no special chars!
OK

Now we could check our passwords.

2 thoughts on “Check password with Perl”

  1. Terrific post however , I was wondering if you could write a
    litte more on this subject? I’d be very thankful if you could elaborate a little bit further.

    Thanks!

  2. This is my first time visit at here and i am genuinely pleassant to read everthing at single place.

Leave a Reply

Your email address will not be published.

five + nineteen =