-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.cpp
executable file
·56 lines (45 loc) · 1.13 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
#include "user.h"
using namespace std;
User::User() : name_("unknown"), balance_(0.0), type_(1)
{
}
User::User(std::string name, double balance, int type, unsigned long long password) :
name_(name), balance_(balance), type_(type), password_(password)
{
}
User::~User()
{
}
std::string User::getName() const
{
return name_;
}
double User::getBalance() const
{
return balance_;
}
void User::deductAmount(double amt)
{
balance_ -= amt;
}
bool User::login(std::string password) {
if(password.length() <= 8){
unsigned long long bigNum = 0;
for(size_t i = 0; i < password.size(); i++){
bigNum = (128 * bigNum) + (int)(password[i]);
}
unsigned int intArr[4] = {0,0,0,0};
int i = 0;
while(bigNum > 0){
intArr[i++] = (bigNum % 65521);
bigNum /= 65521;
}
unsigned long long ans = ((45912 * intArr[3]) + (35511 * intArr[2]) + (65169 * intArr[1]) + (4625 * intArr[0])) % 65521;
return ans == password_;
}
return false;
}
void User::dump(std::ostream& os)
{
os << name_ << " " << balance_ << " " << type_ << endl;
}