-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIs_Password_Valid.cpp
More file actions
62 lines (54 loc) · 889 Bytes
/
Is_Password_Valid.cpp
File metadata and controls
62 lines (54 loc) · 889 Bytes
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
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
bool isValid(string password)
{
const char *c = password.c_str(); //used c_str to treat the const char as string
int len=password.length();
int letter_count=0;
int digit_count=0;
for(int i=0;i<len;i++)
{
if(isalnum(c[i]))
{
if(isalpha(c[i]))
{
letter_count++;
}
else if(isdigit(c[i]))
{
digit_count++;
}
}
else
{
cout<< "INVALID CHARACTER!\n";
return false;
}
}
//letter condition
if(letter_count>0 && digit_count>=2 && len>=10)
{
return true;
}
else
{
return false;
}
}
int main()
{
string str;
cout<< "Enter the string: ";
getline(cin,str);
if(isValid(str))
{
cout << "It is a Valid password!";
}
else
{
cout << "It is not a Valid password!";
}
return 0;
}