-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithms.cpp
executable file
·168 lines (125 loc) · 3.83 KB
/
algorithms.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
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
166
167
168
//==================================================================================
// Name : algorithms.cpp
// Author : Julien Thibodeau
// Description : Algorithms for authentificate.cpp in C++, Ansi-style
//==================================================================================
#include "utils.cpp"
#include "FileReader.cpp"
#include "FileWriter.cpp"
void addEntry()
{
FileWriter fileWriter;
std::cout << "Password for decrypt file : ";
std::string pwdFile = GetTextCinMax50char();
if (!fileWriter.validatepwdFile(pwdFile))
{
return;
}
std::cout << "Password for data entries : ";
std::string pwdContent = GetTextCinMax50char();
if (!fileWriter.validatepwdContent(pwdFile, pwdContent))
{
return;
}
DataInfosJsonRowWriter entryInfos;
std::vector<std::string> data;
do
{
std::cout << "Url : ";
entryInfos.url = GetTextCinMax50char();
std::cout << "User : ";
entryInfos.user = GetTextCinMax50char();
std::cout << "Password : ";
entryInfos.pwd = GetTextCinMax50char();
} while (validateData());
fileWriter.saveEntryInfos(entryInfos, pwdFile, pwdContent);
std::cout << "Saved entry infos succesfully." << std::endl;
}
void RemoveAnEntry()
{
FileReader fileReader;
std::cout << "Password for decrypt file : ";
std::string pwdFile = GetTextCinMax50char();
if (!fileReader.validatepwdFile(pwdFile))
{
return;
}
int numberData = fileReader.printListEntriesInfosCensored(pwdFile);
int lineToSupress = GetLineToSupress(numberData);
if (lineToSupress == 0)
{
return;
}
FileWriter fileWriter;
fileWriter.saveDeletedRowEntryInfos(lineToSupress, pwdFile);
std::cout << "Deleted row succesfully." << std::endl;
}
void ListEntries()
{
FileReader fileReader;
std::cout << "Password for decrypt file : ";
std::string pwdFile = GetTextCinMax50char();
if (!fileReader.validatepwdFile(pwdFile))
{
return;
}
fileReader.printListEntriesInfosCensored(pwdFile);
int trial = 0;
std::string pwdContent;
bool success = false;
do
{
std::cout << "Password for data entries : ";
pwdContent = GetTextCinMax50char();
if (!fileReader.validatepwdContent(pwdFile, pwdContent))
{
}
else
{
success = true;
break;
}
trial++;
} while (trial < 3);
if (!fileReader.validatepwdContent(pwdFile, pwdContent))
{
return;
}
fileReader.printListEntriesInfosDecrypted(pwdFile, pwdContent);
}
void ModifyPasswordFile()
{
FileReader fileReader;
std::cout << "Old password for decrypt/encrypt file : ";
std::string oldPwdFile = GetTextCinMax50char();
if (!fileReader.validatepwdFile(oldPwdFile))
{
return;
}
std::cout << "New password for decrypt/encrypt file : ";
std::string newPwdFile = GetTextCinMax50char();
FileWriter fileWriter;
fileWriter.changepwdFile(oldPwdFile, newPwdFile);
std::cout << "Changed password file succesfully." << std::endl;
}
void ModifyPasswordAccessEntries()
{
FileReader fileReader;
std::cout << "Password for decrypt file : ";
std::string pwdFile = GetTextCinMax50char();
if (!fileReader.validatepwdFile(pwdFile))
{
return;
}
std::cout << "Old password for data entries : ";
std::string oldPwdContent = GetTextCinMax50char();
if (!fileReader.validatepwdContent(pwdFile, oldPwdContent))
{
return;
}
std::cout << "New password for data entries : ";
std::string newPwdContent = GetTextCinMax50char();
FileWriter fileWriter;
fileWriter.changepwdContent(pwdFile, oldPwdContent, newPwdContent);
std::cout << "Changed password content succesfully." << std::endl;
}