Minimum characters required to make a password strong | Python3 program to find minimum number of characters required to be added to make a password strong ; Function to count minimum number of characters ; Create the patterns to search digit , upper case alphabet , lower case alphabet and special character ; If no digits are present ; If no upper case alphabet is present ; If no lower case alphabet is present ; If no special character is is present ; Check if the string length after adding the required characters is less than 8 ; Add the number of characters to be added ; Driver code
import re NEW_LINE def countCharacters ( password ) : NEW_LINE INDENT count = 0 NEW_LINE digit = re . compile ( " ( \\d ) " ) NEW_LINE upper = re . compile ( " ( [ A - Z ] ) " ) NEW_LINE lower = re . compile ( " ( [ a - z ] ) " ) NEW_LINE spChar = re . compile ( " ( \\W ) " ) NEW_LINE if ( not re . search ( digit , password ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if ( not re . search ( upper , password ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if ( not re . search ( lower , password ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if ( not re . search ( spChar , password ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if ( ( count + len ( password ) ) < 8 ) : NEW_LINE INDENT count = count + 8 - ( count + len ( password ) ) NEW_LINE DEDENT return count NEW_LINE DEDENT password1 = " Geeksforgeeks " NEW_LINE print ( countCharacters ( password1 ) ) NEW_LINE password2 = " Geeks1" NEW_LINE print ( countCharacters ( password2 ) ) NEW_LINE