-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUserManager.cpp
More file actions
38 lines (31 loc) · 1.31 KB
/
UserManager.cpp
File metadata and controls
38 lines (31 loc) · 1.31 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
#include "UserManager.h"
namespace trainsys {
UserManager::UserManager(const char *filename): userInfoTable(filename) {
}
void UserManager::insertUser(const UserID &userID, const char *username, const char* password, int privilege) {
userInfoTable.insert(userID, UserInfo(userID, username, password, privilege));
}
bool UserManager::existUser(const UserID &userID) {
return userInfoTable.contains(userID);
}
UserInfo UserManager::findUser(const UserID& userID) {
return userInfoTable.find(userID);
}
void UserManager::removeUser(const UserID& userID) {
userInfoTable.remove(userID);
}
void UserManager::modifyUserPrivilege(const UserID& userID, int newPrivilege) {
UserInfo info = findUser(userID);
removeUser(userID);
insertUser(userID, info.username, info.password, newPrivilege);
}
void UserManager::modifyUserPassword(const UserID& userID, const char* newPassword) {
UserInfo info = findUser(userID);
int len = strlen(newPassword);
if (len > MAX_PASSWORD_LEN) len = MAX_PASSWORD_LEN;
memcpy(info.password, newPassword, len);
info.password[len] = '\0';
removeUser(userID);
insertUser(userID, info.username, info.password, info.privilege);
}
} // namespace trainsys