Last active
December 17, 2021 21:10
-
-
Save mrmarkuz/9b05e0bb10e74a6e101940ffb5066a71 to your computer and use it in GitHub Desktop.
Script to check password complexity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl -w | |
| # This Script will check password complexity | |
| # Got this script from https://www.mylinuxplace.com/tag/check-password-script/ and adapted it to work... | |
| $min_length=8; | |
| $min_upercase=1; | |
| $min_lowercase=1; | |
| $min_digits=1; | |
| $min_specialchar=1; | |
| $specialchars='!,@,$,#,%,^,&,*,(,),-,_,+,='; | |
| # get the password from standard input ( possible to pipe ) | |
| $str_pass=<STDIN>; | |
| # now lets start check and update the counters is we find something | |
| # but first lets set all counters to zero | |
| $ctr_length=-1; | |
| $ctr_upercase=0; | |
| $ctr_lowercase=0; | |
| $ctr_digits=0; | |
| $ctr_specialcar=0; | |
| # conver the string to array | |
| @array_pass = split('',$str_pass); | |
| foreach $pass_char (@array_pass) | |
| { | |
| $ctr_length++; | |
| # check uppercase | |
| if($pass_char =~ /[A-Z]/) | |
| { | |
| $ctr_upercase++; | |
| } | |
| # check lowercase | |
| elsif($pass_char =~ /[a-z]/) | |
| { | |
| $ctr_lowercase++; | |
| } | |
| # check digits | |
| elsif($pass_char =~ /[0-9]/) | |
| { | |
| $ctr_digits++; | |
| } | |
| # check special chars | |
| elsif($pass_char =~ /[$specialchars]/) | |
| { | |
| $ctr_specialcar++; | |
| } | |
| } | |
| # check if we reached minimal length | |
| if($ctr_length<$min_length) | |
| { | |
| print "Too short, minimum $min_length and got $ctr_length \n"; | |
| exit 1; | |
| } | |
| # check if we reached minimal UPER case | |
| if($ctr_upercase<$min_upercase) | |
| { | |
| print "Not enough uppercase, minimum $min_upercase and got $ctr_upercase \n"; | |
| exit 2; | |
| } | |
| # check if we reached minimal lower case | |
| if($ctr_lowercase<$min_lowercase) | |
| { | |
| print "Not enough lowercase, minimum $min_lowercase and got $ctr_lowercase \n"; | |
| exit 3; | |
| } | |
| # check if we reached minimal digits | |
| if($ctr_digits<$min_digits) | |
| { | |
| print "Not enough digits, minimum $min_digits and got $ctr_digits \n"; | |
| exit 4; | |
| } | |
| # check if we reached minimal special characters | |
| if($ctr_specialcar<$min_specialchar) | |
| { | |
| print "Not enough special characters, minimum $min_specialchar and got $ctr_specialcar \n"; | |
| exit 5; | |
| } | |
| # if you got up to here , meaning you passed it all with success | |
| # we can now return a non error exit | |
| exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment