-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode
More file actions
201 lines (190 loc) · 4.19 KB
/
Copy pathcode
File metadata and controls
201 lines (190 loc) · 4.19 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <iostream>h
#define usersSize 100
using namespace std;
struct account {
string username;
string password;
string email;
};
struct transactions {
float transactionAmount;
string transactionType;
string reciever;
};
struct user {
int age;
float balance;
account userAccount;
transactions userTransaction[100];
bool frozen = 0;
int accNum;
string phoneNum;
int transactionCount = 0;
};
int anotherUserIndex, thisUserIndex;
bool signup(user users[]);
bool findEmail(string email, user users[]);
bool findPhoneNum(string phoneNum, user users[]);
bool findAccNum(int accNum, user users[]);
bool login (user users[]);
bool findLogin(string email, string password,user users[]);
bool wrongEmail(string Email,user users[]);
bool wrongPassword(string password,user users[]);
bool weakPassword(string password, user users[]);
int main()
{
char ans;
user users[usersSize];
while (!signup(users)) {
cout << "Do you want to retry? (N/Y)" << endl;
cin >> ans;
if (ans == 'n' || ans == 'N')break;
}
while (!login(users)) {
cout << "Do you want to retry? (N/Y)" << endl;
cin >> ans;
if (ans == 'n' || ans == 'N')break;
}
}
//ask ahmed amr
bool signup(user users[]) {
user temp;
cout << "Enter your name: " << endl;
cin >> temp.userAccount.username;
cout << "Enter your email: " << endl;
cin >> temp.userAccount.email;
if (findEmail(temp.userAccount.email, users)) {
cout << "This email already exists." << endl;
return false;
}
if (temp.userAccount.email.find("@user.bank") == string::npos) {
cout << "Invalid mail format." << endl;
return false;
}
cout << "Enter your password: " << endl;
cin >> temp.userAccount.password;
if (weakPassword(temp.userAccount.password,users))
{
cout << "Weak password\n";
return false;
}
cout << "Enter your age: " << endl;
cin >> temp.age;
if (temp.age < 21) {
cout << "You must be 21 or above" << endl;
return false;
}
cout << "Enter balance: " << endl;
cin >> temp.balance;
if (temp.balance < 200) {
cout << "Minimum balance is 200 !" << endl;
return false;
}
cout << "Enter phone number: " << endl;
cin >> temp.phoneNum;
if (findPhoneNum(temp.phoneNum, users)) {
cout << "This phone number is already in use." << endl;
return false;
}
temp.accNum = (rand() % 101) + 100;
while (findAccNum(temp.accNum, users)) {
temp.accNum = (rand() % 101) + 100;
}
for (int i = 0; i < usersSize; i++) {
if (users[i].userAccount.email.empty()) {
users[i] = temp;
}
}
}
bool findEmail(string email, user users[]) {
for (int i = 0; i < usersSize; i++) {
if (email == users[i].userAccount.email) {
return true;
}
}
return false;
}
bool findPhoneNum(string phoneNum, user users[]) {
for (int i = 0; i < usersSize; i++) {
if (phoneNum == users[i].phoneNum) {
return true;
}
}
return false;
}
bool findAccNum(int accNumber, user users[]) {
for (int i = 0; i < usersSize; i++) {
if (accNumber == users[i].accNum) {
anotherUserIndex = i;
return true;
}
}
return false;
}
//Ask ziad abdelaziz
bool login(user users[])
{
user temp;
cout << "Please enter your email: \n";
cin >> temp.userAccount.email;
cout << "please enter your password: \n";
cin >> temp.userAccount.password;
if (findLogin(temp.userAccount.email, temp.userAccount.password, users))
{
cout << "Logged in successfully\n";
return true;
}
else
{
cout << "Failed to login ";
if (wrongEmail(temp.userAccount.email, users))
{
cout << "wrong email\n";
}
if (wrongPassword(temp.userAccount.password, users))
{
cout << "wrong password\n";
}
}
}
bool findLogin(string email, string password, user users[])
{
for (int i = 0; i < usersSize; i++)
{
if (email == users[i].userAccount.email && password == users[i].userAccount.password)
{
return true;
}
}
return false;
}
bool wrongEmail(string email, user users[])
{
for (int i = 0; i < usersSize; i++)
{
if (email != users[i].userAccount.email)
{
return true;
}
}
return false;
}
bool wrongPassword(string password,user users[])
{
for (int i = 0; i < usersSize; i++)
{
if (password != users[i].userAccount.password)
{
return true;
}
}
return false;
}
bool weakPassword(string password, user users[])
{
if (password.size() <= 3)
{
return true;
}
return false;
}