-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
120 lines (100 loc) · 2.47 KB
/
main.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// C++ code to validate a password
#include<bits/stdc++.h>
using namespace std;
// A utility function to check
// whether a password is valid or not
bool isValid(string password)
{
// For checking if password length
// is between 8 and 15
if (!((password.length() >= 8) &&
(password.length() <= 15)))
return false;
// To check space
if (password.find(" ") !=
std::string::npos)
return false;
if (true)
{
int count = 0;
// Check digits from 0 to 9
for(int i = 0; i <= 9; i++)
{
// To convert int to string
string str1 = to_string(i);
if (password.find(str1) !=
std::string::npos)
count = 1;
}
if (count == 0)
return false;
}
// For special characters
if (!((password.find("@") != std::string::npos) ||
(password.find("#") != std::string::npos) ||
(password.find("!") != std::string::npos) ||
(password.find("~") != std::string::npos) ||
(password.find("$") != std::string::npos) ||
(password.find("%") != std::string::npos) ||
(password.find("^") != std::string::npos) ||
(password.find("&") != std::string::npos) ||
(password.find("*") != std::string::npos) ||
(password.find("(") != std::string::npos) ||
(password.find(")") != std::string::npos) ||
(password.find("-") != std::string::npos) ||
(password.find("+") != std::string::npos) ||
(password.find("/") != std::string::npos) ||
(password.find(":") != std::string::npos) ||
(password.find(".") != std::string::npos) ||
(password.find(",") != std::string::npos) ||
(password.find("<") != std::string::npos) ||
(password.find(">") != std::string::npos) ||
(password.find("?") != std::string::npos) ||
(password.find("|") != std::string::npos)))
return false;
if (true)
{
int count = 0;
// Checking capital letters
for(int i = 65; i <= 90; i++)
{
// Type casting
char c = (char)i;
string str1(1, c);
if (password.find(str1) !=
std::string::npos)
count = 1;
}
if (count == 0)
return false;
}
if (true)
{
int count = 0;
// Checking small letters
for(int i = 90; i <= 122; i++)
{
// Type casting
char c = (char)i;
string str1(1, c);
if (password.find(str1) !=
std::string::npos)
count = 1;
}
if (count == 0)
return false;
}
// If all conditions fails
return true;
}
// Driver code
int main()
{
string password1;
cout<<"Input Password\n";
cin>>password1;
if (isValid(password1))
cout << "Valid Password" << endl;
else
cout << "Invalid Password" << endl;
}