-
Notifications
You must be signed in to change notification settings - Fork 2
/
user.cpp
61 lines (52 loc) · 1.19 KB
/
user.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
#include "user.h"
user::user() : hashedPassword(""),userID("")
{
user::setUsername();
user::setPassword();
}
int user::getch() {
struct termios oldt, newt;
int ch;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}
void user::getPass(string &pass) {
char ch;
while(getch() != '\n');
ch = getch();
while(ch != 10 && ch != 13){//character 13 is enter
if (ch == 10 || ch == 13)
break;
if (ch == 127 && pass.size() > 0)
pass.pop_back();
else if (ch > 1 && ch < 255)
pass.push_back(ch);
ch = getch();
}
}
void user::setUsername() {
cout << "Enter a username:\n";
cin >> username;
}
void user::setPassword() {
cout << "Enter a password:\n";
getPass(password);
cout << "\n";
}
void user::setUserID(string& ID)
{
this->userID = ID;
}
void user::setHashedPassword(string& hashpass)
{
this->hashedPassword = hashpass;
}
string user::getPassword() { return password; };
string user::getUsername() { return username; };
string user::getUserID(){ return userID; }
string user::getHashedPassword(){ return hashedPassword; }