Question: 1 2 . Password Validation There are n passwords in the form of a string array of passwords [ n ] . There is also

12. Password Validation
There are n passwords in the form of a string array of passwords[n]. There is also a dictionary dict_words[m] that contains m weak passwords.
Classify each of the n passwords as "weak" or "strong".
A password is "weak" if any of these conditions are met.
The password is in the dictionary.
A substring of the password is a word in the dictionary.
The password is all numerical, i.e., consisting of characters from ('0' to '9').
All characters are uppercase('A' to 'Z') or all of them are lowercase('a' to 'z').
The password is shorter than 6 characters.
Implement a prototype password validation service.
Given a list of n strings, passwords, and m strings, common_words, for each of the passwords, report "strong" or "weak" based on the conditions.
Example
Suppose n =5, m =3, passwords =["iliketo CoDe", "teaMAKEsmehappy", "abracadabra", "password", "blackcoffeelSthebest"], common_words =["coffee", "coding", "happy"]
[05/05,13:45] Kartik: password
strong/weak
Remarks
iliketoCoDe
strong
teaMAKEsmehappy
weak
Contains "happy"
abracadabra
strong
password
strong
blackcoffeelSthebest
weak
C
ny
Contains "coffee"
Function Description Complete the function getPassword Strength.
getPasswordStrength has the following parameters:
string passwords[n]: the list of passwords to check
string common_words[m]: the list of dictionary words
Returns:
string[n]: the strengths of the passwords
Constraints
1<= n <=103
1<= m <=105
1<= common_words[i]<20
1<= passwords[i]<=20
The passwords consist of lowercase, uppercase, and numeric characters only.
[05/05,13:45] Kartik: Input Format For Custom Testing
The first line contains an integer, n, the number of elements in passwords.
Each line / of the n subsequent lines contains a string, passwords[i].
The next line contains an integer, m, the number of elements in dict_words.
Each line of the m subsequent lines contains a string, dict_words[i].
Sample Case 0
Sample Input For Custom Testing
STDIN
FUNCTION
3-> n =3
hello -> passwords[]=["hello", "chargeR", "pass123"]
charger
pass123
5
->
m =5
hello common_words[]=["hello","123", "password", "xyz","999"]
123
password
xyz
999
Sample Output
weak
strong
weak
Explanation
The first password is weak as it contains only five
[05/05,13:45] Kartik: Explanation
The first password is weak as it contains only five characters and the last password is weak as it contains "123" as a substring.
Sample Case 1
Sample Input For Custom Testing
STDIN
FUNCTION
3
->
12345
n =3
-> passwords[]=["12345", "YUIOYES", "qwertyuiop"]
YUIOYES
qwertyuiop
2
m =2
ty "xyz"]
common_words[]=["ty",
C
xyz
Sample Output
weak
weak
weak
Explanation
The passwords contain all numeric, all uppercase letters, and all lowercase letters respectively.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!