Given a string str denoting a password, the task is to count the minimum characters that need to be added to make the password strong.
A password is said to be strong if it satisfies the following criteria:
- It contains at least 8 characters.
- It contains at least one digit.
- It contains at least one lower case alphabet.
- It contains at least one upper case alphabet.
- It contains at least one special character which includes !@#$%^&*()-+
Input: str = “Geeksforgeeks”
By adding one digit and one special character we can make the password strong.
Input: str = “Geeks1”
A special character along with one more character needs to be added to make the password strong.
Approach: This problem can be solved using Regular Expressions:
- Create the regular expressions to check digit, special character, upper case and lower case alphabet.
- Compile the regular expressions and find matches with the password string.
- Increase the counter, say count, to add characters whenever any of the regular expression does not match.
- After adding count characters to the password string, check if the length of the string is less than 8 or not. If so, add the difference to count and print.
Below is the implementation of the above approach.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Strong Password Suggester Program
- Minimum characters to be replaced to make frequency of all characters same
- Minimum number of pairs required to make two strings same
- Minimum number of operations required to make two strings equal
- Minimum number of swaps required to make the string K periodic
- Minimum operations required to make the string satisfy the given condition
- Minimum swaps required to make a binary string alternating
- Minimum number of given operations required to make two strings equal
- Minimum swaps required to make a binary string divisible by 2^k
- Minimum characters to be deleted from the end to make given two strings equal
- Minimum operations to make frequency of all characters equal K
- Find the minimum number of preprocess moves required to make two strings equal
- Minimum Number of Manipulations required to make two Strings Anagram Without Deletion of Character
- Minimum characters to be deleted from the beginning of two strings to make them equal
- Minimum replacements in a string to make adjacent characters unequal
- Minimum characters to be added at front to make string palindrome
- Minimum replacements to make adjacent characters unequal in a ternary string
- Minimum addition/removal of characters to be done to make frequency of each character prime
- Minimum replacements to make adjacent characters unequal in a ternary string | Set-2
- Minimum number of characters to be removed to make a binary string alternate
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.