-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordValidator.js
More file actions
82 lines (73 loc) · 1.98 KB
/
PasswordValidator.js
File metadata and controls
82 lines (73 loc) · 1.98 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var input = prompt('Please enter password to check if valid');
function checkUpperCase(input){
for(var i = 0; i < input.length; i++){
if(input[i] === input[i].toUpperCase()){
return true;
}
}
return false;
}
function checkLowerCase(input){
for(var i = 0; i < input.length; i++){
if(input[i] === input[i].toLowerCase()){
return true;
}
}
return false;
}
function checkLength(input){
if(input.length < 8){
return false;
}
return true;
}
function checkSpecialChar(input){
var special = ['!','@', '#', "$", "%", '^', '&', "*", ',','.','/','?','<','>'];
for(var i = 0; i < input.length; i++){
for(var j = 0; j < special.length; j++){
if(input[i] === special[j]){
return true;
}
}
}
return false;
}
function checkNumber(input){
var numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
for(var i = 0; i < input.length; i++){
for(var j = 0; j < numbers.length; j++){
if(input[i] === numbers[j]){
return true;
}
}
}
return false;
}
function isValid(input){
var upper = checkUpperCase(input);
var lower = checkLowerCase(input);
var length = checkLength(input);
var specialChar = checkSpecialChar(input);
var number = checkNumber(input);
if(upper === true && lower === true && length === true && specialChar === true && number === true){
console.log("Your Password is secure.");
} else{
console.log("Your password is not secure. Please adhere to the following restrictions ");
if(upper === false){
console.log(" >Has at least one uppercase letter");
}
if(lower === false){
console.log(" >Has at least one lowercase letter");
}
if(length === false){
console.log(" >Is at least 8 characters long");
}
if(specialChar === false){
console.log(" >Has at least one special character");
}
if(number === false){
console.log(" >Has at least one number");
}
}
}
isValid(input);