forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrong Password Checker II.js
60 lines (51 loc) · 1.63 KB
/
Strong Password Checker II.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
59
60
const checkLen = (password) => password.length >= 8;
const checkSmallLetter = (password) => {
for(let i=0;i<password.length;i++){
const ind = password.charCodeAt(i);
if(ind > 96 && ind < 123){
return true;
}
}
return false;
}
const checkCapitalLetter = (password) => {
for(let i=0;i<password.length;i++){
const ind = password.charCodeAt(i);
if(ind > 64 && ind < 91){
return true;
}
}
return false;
}
const checkDigit = (password) => {
for(let i=0;i<password.length;i++){
const ind = password.charCodeAt(i);
if(ind > 47 && ind < 58){
return true;
}
}
return false;
}
const checkSpecialChar = (password) => {
const str = "!@#$%^&*()-+";
for(let i=0;i<str.length;i++){
if(password.includes(str[i])) return true;
}
return false;
}
const checkAdjacentMatches = (password) => {
for(let i=1;i<password.length;i++){
if(password[i] === password[i-1]) return false;
}
return true;
}
var strongPasswordCheckerII = function(password) {
const lenValidity = checkLen(password);
const smallLetterValidity = checkSmallLetter(password);
const capitalLetterValidity = checkCapitalLetter(password);
const digitValidity = checkDigit(password);
const specialCharValidity = checkSpecialChar(password);
const adjacentMatchesValidity = checkAdjacentMatches(password);
const passwordIsStrong = lenValidity && smallLetterValidity && capitalLetterValidity && digitValidity && specialCharValidity && adjacentMatchesValidity;
return passwordIsStrong;
};