-
Notifications
You must be signed in to change notification settings - Fork 44
/
strongPassword.js
58 lines (52 loc) · 1.82 KB
/
strongPassword.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function minimumNumber(n, password) {
/* Find the missing must have characters in the password and return it if by adding them the resulting password length is
greater than or equal to 6 else if the password length is still less than 6 characters then return the no. of missing must
have characetrs along with the no. of characters to be added to make the password length equal to 6.*/
var upperCaseChar=0;
var lowerCaseChar=0;
var specialChar=0;
var digit=0;
var musthaveChars=0;
for(let i=0; i<n; i++){
if(password.charCodeAt(i)>=65 && password.charCodeAt(i)<=90){
upperCaseChar++;
}
else if(password.charCodeAt(i)>=97 && password.charCodeAt(i)<=122){
lowerCaseChar++;
}
else if(password.charAt(i)=='!' || password.charAt(i)=="@" || password.charAt(i)=="#" ||
password.charAt(i)=="$" || password.charAt(i)=="%" || password.charAt(i)=="^" ||
password.charAt(i)=="*" || password.charAt(i)=="&" || password.charAt(i)=="(" ||
password.charAt(i)==")" || password.charAt(i)=="-" || password.charAt(i)=="+"){
specialChar++;
}
else if(password.charCodeAt(i)>=48 && password.charCodeAt(i)<=57){
digit++;
}
}
if(upperCaseChar==0){
musthaveChars++;
}
if(lowerCaseChar==0){
musthaveChars++;
}
if(specialChar==0){
musthaveChars++;
}
if(digit==0){
musthaveChars++;
}
var len= n+musthaveChars;
if(len<6){
return ((6-len) + musthaveChars);
}
else{
return musthaveChars;
}
}
function main() {
var n = parseInt(readLine());
var password = readLine();
var answer = minimumNumber(n, password);
process.stdout.write("" + answer + "\n");
}