-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatm_front.py
170 lines (147 loc) · 4.64 KB
/
atm_front.py
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
import db
import faceRecognitionProject as fr
import otp
import random
current_user = 0
current_id = 0
# functions
def uid_generator():
global current_user, current_id
uid = random.randint(1000, 10000)
for eid in range(len(db.acc)):
if uid == db.acc[eid].value:
current_id = eid
current_user = uid
print("Account ID Generated: ", uid)
return uid
# replaced with uid generator function
def exist(uid):
# Check if the user id exist in database
global current_user, current_id
for eid in range(len(db.acc)):
if uid == db.acc[eid].value:
current_id = eid
current_user = uid
return True
return False
def match(upw):
# Check if the user id match its password in database
if upw == db.pwd[current_id].value:
return True
else:
return False
def withdraw(i):
# withdraw money
db.backup()
db.balance[current_id].value = db.balance[current_id].value - i
db.save_2()
print("RM", i, "have been withdrawn")
def deposit(i):
# deposit
db.backup()
db.balance[current_id].value = db.balance[current_id].value + i
db.save_2()
print("RM", i, "have been deposited")
def user_action():
print("")
print("Welcome, ", db.nam[current_id].value)
print("Choose an action:")
print("1 - Check Balance")
print("2 - Withdraw")
print("3 - Deposit")
print("4 - Exit")
ac = int(input(""))
if ac == 1:
print("Your current balance is ", db.balance[current_id].value)
user_action()
elif ac == 2:
amount = int(input("Input the amount to be withdrawn: RM"))
user_code = input("Enter OTP: ")
if otp.otp_check(db.secret_key[current_id].value, user_code):
withdraw(amount)
user_action()
else:
print("OTP is wrong. Please try again.")
user_action()
elif ac == 3:
amount = int(input("Input the amount to be deposited: RM"))
user_code = input("Enter OTP: ")
if otp.otp_check(db.secret_key[current_id].value, user_code):
deposit(amount)
user_action()
else:
print("OTP is wrong. Please try again.")
user_action()
elif ac == 4:
print("Thanks for using XXX services.")
else:
print("Invalid action, please try again.")
user_action()
# main ATM
def login():
print("")
u_id = int(input("Enter your acc number: "))
if exist(u_id):
print("Choose a login option: ")
print("1 - Login with password")
print("2 - Login with FaceID")
print("3 - Cancel")
u_c = int(input())
if u_c == 1:
u_p = int(input("Enter your acc pin: "))
if match(u_p):
user_code = input("Enter OTP: ")
if otp.otp_check(db.secret_key[current_id].value, user_code):
print("Access Granted")
user_action()
else:
print("OTP is wrong. Please try again")
login()
else:
print("Sorry, you account id or password are wrong.")
main()
elif u_c == 2: # face recog
print("Press Q to cancel verification.")
if fr.verifi(current_id):
user_action()
else:
print("Verification failed, please try again.")
main()
elif u_c == 3:
main()
else:
print("Invalid action, please try again")
main()
else:
print("Sorry, you account id or password are wrong.")
main()
def register():
print("")
u_i1 = uid_generator()
u_p1 = int(input("Please enter password: "))
u_n1 = input("Please input account name: ")
u_e1 = input("Please enter your email address: ")
u_h1 = input("Please enter your hand phone number: ")
print("Press Q when your face is boxed to capture your face id.")
u_face = fr.registerEncodings()
db.registration(u_i1, u_n1, u_p1, u_e1, u_h1, u_face)
print("Register success!")
main()
def main():
print("")
print("Welcome to XXX.")
print("Please choose an option:")
print("1 - Login")
print("2 - Register")
u_c = int(input())
if u_c == 1:
login()
elif u_c == 2:
register()
else:
print("Invalid action, please try again")
main()
try:
main()
except:
print('Something went wrong, proceed to exit.')