-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplePasswordValidator.js
More file actions
43 lines (33 loc) · 1.26 KB
/
simplePasswordValidator.js
File metadata and controls
43 lines (33 loc) · 1.26 KB
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
/**
* -------------------------------------------------------
* Programming Question : Simple Password Validator
* -------------------------------------------------------
**/
// Q. WAF called simplePasswordValidator that take a single parameter.
//? The password must contain at least one lowercasem one uppercase letter and one digit.
//? The length of password must be at least 8 characters.
//? The function should return true if the password meets all the criteria, otherwise. It should return false.
//?
function simplePasswordValidator(password) {
let hasUpper = false;
let hasLower = false;
let hasNumber = false;
for(let char of password){
if(char.charCodeAt(0) >= 65 && char.charCodeAt(0) <= 90){
hasUpper = true;
}else if(char.charCodeAt(0) >= 97 && char.charCodeAt(0) <= 122){
hasLower = true;
}else if(!isNaN((Number(char)))){
hasNumber = true
}
}
if(!hasUpper || !hasLower || !hasNumber || password.length < 8){
return false;
}
return true;
}
console.log(simplePasswordValidator("safewfwef"));
console.log(simplePasswordValidator("fewfwef"));
console.log(simplePasswordValidator("safewfwef1"));
console.log(simplePasswordValidator("safewfw1Aef"));
console.log(simplePasswordValidator("safew12Aafwef"));