-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
165 lines (152 loc) · 3.96 KB
/
Copy pathmain.cpp
File metadata and controls
165 lines (152 loc) · 3.96 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
struct Account{
string website;
string username;
string password;
};
vector<Account> accounts;
void addAccount();
void viewAccount();
void searchAccount();
void deleteAccount();
void checkPasswordStrength();
int main(){
int choice;
while(true){
cout<<"Welcome to SecureKey, your trusted password manager!\n";
cout<<"1. Add Account"<<endl;
cout<<"2. View Account"<<endl;
cout<<"3. Search Account"<<endl;
cout<<"4. Delete Account"<<endl;
cout<<"5. Password Strength Checker"<<endl;
cout<<"6. Exit"<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
switch(choice)
{
case 1:
addAccount();
break;
case 2:
viewAccount();
break;
case 3:
searchAccount();
break;
case 4:
deleteAccount();
break;
case 5:
checkPasswordStrength();
break;
case 6:
cout<<"Thank you!\n";
return 0;
default:
cout<<"Invalid choice"<<endl;
}
}
}
void addAccount(){
Account temp;
cout<<endl<<"Enter website: ";
cin>>temp.website;
cout<<"Enter username: ";
cin>>temp.username;
cout<<"Enter password: ";
cin>>temp.password;
accounts.push_back(temp);
cout<<"\nAccount added successfully!\n\n";
}
void viewAccount(){
if(accounts.empty()){
cout<<"No accounts found\n\n";
return;
}
for(int i=0;i<accounts.size();i++){
cout<<"Account "<<i+1<<":\n";
cout<<"Website: "<<accounts[i].website<<endl;
cout<<"Username: "<<accounts[i].username<<endl;
cout<<"Password: "<<accounts[i].password<<endl<<endl<<"============================="<<endl;
}
}
void searchAccount(){
cout<<"Enter website to search: ";
string website;
cin >> website;
for(int i=0; i<accounts.size(); i++){
if(accounts[i].website==website){
cout<<"Account Found!"<<endl;
cout<<"Website: "<<accounts[i].website<<endl;
cout<<"Username: "<<accounts[i].username<<endl;
cout<<"Password: "<<accounts[i].password<<endl<<endl;
return;
}
}
cout<<"Account not found.\n\n";
}
void deleteAccount(){
string website;
cout<<"Enter website to delete: ";
cin >> website;
for(int i=0; i<accounts.size(); i++){
if(accounts[i].website==website){
accounts.erase(accounts.begin() + i);
cout<<"\nAccount deleted successfully!\n\n";
return;
}
}
cout<<"\nAccount not found.\n";
}
void checkPasswordStrength(){
string password;
cout<<"Enter Password: ";
cin>>password;
bool hasUpper = false;
bool hasLower = false;
bool hasDigit = false;
bool hasSpecial = false;
for(int i=0; i<password.length(); i++){
if(isupper(password[i])){
hasUpper= true;
}
if(islower(password[i])){
hasLower= true;
}
if(isdigit(password[i])){
hasDigit= true;
}
if(!isalnum(password[i])){
hasSpecial= true;
}
}
int score=0;
if(password.length()>=8){
score++;
}
if(hasUpper){
score++;
}
if(hasLower){
score++;
}
if(hasDigit){
score++;
}
if(hasSpecial){
score++;
}
if(password.length()<8 || score<=2){
cout<<"Weak Password\n\n";
}
else if(score==5){
cout<<"Strong Password\n\n";
}
else{
cout<<"Medium Password\n\n";
}
}