-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
157 lines (153 loc) · 5.62 KB
/
Copy pathmain.cpp
File metadata and controls
157 lines (153 loc) · 5.62 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
#include "profile.h"
#include "Passwords.h"
#include "User.h"
#include <boost/algorithm/string.hpp>
using namespace std;
int main(int argc, char *argv[]) {
string command1, command2, name, password;
bool g1 = true;
cout << "Enter \"Login\" or \"Create\" to start using the app."
"\nEnter --help or -h to get information about app and commands.\n";
while (g1) {
cin >> command1;
boost::algorithm::to_lower(command1);
if (command1 == "login" || command1 == "l") {
cout << "Enter your login details.\nEmail / Username: ";
cin >> name;
cout << "Password: ";
cin >> password;
User u1(name, password);
if (u1.getPermission()) {
psw p1(u1.getUser_ID(), password, u1.getPermission());
while (true) {
cout << "Enter add, get, update or delete command: \n";
cin >> command2;
boost::algorithm::to_lower(command2);
int a;
if (command2 == "get") {
vector<string> passwords = p1.SelectAll();
cout << "Type number to get password: ";
cin >> a;
//if a is letter = infinite loop
if (a <= 0 || a > passwords.size()) {
cout << "Put valid number next to \"Name\"!\n";
break;
} else {
cout << passwords[a - 1] << endl;
// toClipboard(passwords[a - 1]);
//copy password to clipboard
//cout << "Password has copied to clipboard\nPassword will be removed
//from clipboard after 3 minutes!";
}
} else if (command2 == "add") {
string aname, alogin, apassword, acomment;
cout << "Enter Name: ";
cin >> aname;
cout << "Login: ";
cin >> alogin;
cout << "Password: ";
cin >> apassword;
cout << "And comment if you wish: ";
cin >> acomment;
//option to skip comment(add empty comment)
p1.Insert(aname, alogin, apassword, acomment);
cout << "Added successfully.\n";
//need to know was data inserted or not
} else if (command2 == "update") {
vector<string> passwords = p1.SelectAll();
cout << "Which one do you want to change: ";
cin >> a;
//if a is letter = infinite loop
if (a <= 0 || a > passwords.size()) {
cout << "Put valid number next to \"Name\"!\n";
break;
} else {
cout << "What column do you want to update?\nChoose Name, Login, "
"Password or Comment\n";
string field, new_value;
cin >> field;
boost::algorithm::to_lower(field);
cout << "Input new value: ";
cin >> new_value;
vector<int> v = p1.SelectID();
if (field == "name") {
p1.Update("Name", new_value, "ID", to_string(v[a - 1]));
cout << "Name was updated!\n";
//need to know was data updated or not
} else if (field == "login") {
p1.Update("Login", new_value, "ID", to_string(v[a - 1]));
cout << "Login was updated!\n";
//need to know was data updated or not
} else if (field == "password") {
p1.Update("Password", new_value, "ID", to_string(v[a - 1]));
cout << "Password was updated!\n";
//need to know was data updated or not
} else if (field == "comment") {
p1.Update("Comment", new_value, "ID", to_string(v[a - 1]));
cout << "Comment was updated!\n";
//need to know was data updated or not
} else
cout << "This column doesn't exist!\n";
}
} else if (command2 == "delete" || command2 == "d") {
vector<string> passwords = p1.SelectAll();
cout << "Which one do you want to delete: ";
cin >> a;
//if a is letter = infinite loop
if (a <= 0 || a > passwords.size()) {
cout << "Put valid number next to \"Name\"!\n";
break;
} else {
vector<int> v = p1.SelectID();
p1.Delete("ID", to_string(v[a - 1]));
cout << "Deleted successfully!\n";
}
} else if (command2 == "delete user" || command2 == "du") {
u1.DeleteUser();
cout << name << " account and all it's passwords were deleted.\n";
break;
} else if (command2 == "logout" || command2 == "lo") {
cout << "You logged out!";
break;
} else if (command2 == "exit" || command2 == "quit") {
exit(0);
} else
cout << "Command " << command2 << " doesn't exist!\n";
cout << "\nEnter command: ";
}
} else {
cout << "Enter command: ";
}
} else if (command1 == "create" || command1 == "c") {
cout << "Enter Email / Name: ";
cin >> name;
cout << "Enter Password: ";
cin >> password;
User u1;
u1.AddNewUser(name, password);
cout << "User created successfully\nNow go and login!" << endl;
//options to continue using
} else if (command1 == "settings" || command1 == "s") {
cout << "Option is coming soon";
} else if (command1 == "--help" || command1 == "-h") {
cout << "\nWelcome to Password Manager Console Edition!\n"
"Version: Beta 0.7\nCommands:\n"
"\tlogin or l Logs you in"
"\n\t\t[get] Show you the password, Copies the password to clipboard"
"\n\t\t[add] Adding new account's data for storage"
"\n\t\t[update] Edits existing account's data"
"\n\t\t[delete or d] Removes chosen account"
"\n\t\t[delete user or du] Removes current application's user and all it's data"
"\n\t\t[logout or lo] Logs you out\n"
"\tcreate or c Creates a new user account\n"
"\tsettings or s Sets up configuration options\n"
"\texit or quit Clothes the app\n\n"
"Enter command: ";
} else if (command1 == "quit" || command1 == "exit") {
g1 = false; // or exit(0);
} else {
cout << "Command " << command1 << " doesn't exist!\nEnter command: ";
}
}
return 0;
}