Question: 1 2 . Password Validation There are n passwords in the form of a string array of passwords [ n ] . There is also
Password Validation
There are n passwords in the form of a string array of passwordsn There is also a dictionary dictwordsm 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, ie consisting of characters from to
All characters are uppercaseA to Z or all of them are lowercasea to z
The password is shorter than characters.
Implement a prototype password validation service.
Given a list of n strings, passwords, and m strings, commonwords, for each of the passwords, report "strong" or "weak" based on the conditions.
Example
Suppose n m passwords iliketo CoDe", "teaMAKEsmehappy", "abracadabra", "password", "blackcoffeelSthebest" commonwords coffee "coding", "happy"
: Kartik: password
strongweak
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 passwordsn: the list of passwords to check
string commonwordsm: the list of dictionary words
Returns:
stringn: the strengths of the passwords
Constraints
n
m
commonwordsi
passwordsi
The passwords consist of lowercase, uppercase, and numeric characters only.
: 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, passwordsi
The next line contains an integer, m the number of elements in dictwords.
Each line of the m subsequent lines contains a string, dictwordsi
Sample Case
Sample Input For Custom Testing
STDIN
FUNCTION
n
hello passwordshello "chargeR", "pass
charger
pass
m
hello commonwordshello "password", xyz
password
xyz
Sample Output
weak
strong
weak
Explanation
The first password is weak as it contains only five
: Kartik: Explanation
The first password is weak as it contains only five characters and the last password is weak as it contains as a substring.
Sample Case
Sample Input For Custom Testing
STDIN
FUNCTION
n
passwords "YUIOYES", "qwertyuiop"
YUIOYES
qwertyuiop
m
ty xyz
commonwordsty
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
