-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
74 lines (61 loc) · 2.45 KB
/
test.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
import time
import hashlib
from bitcoin import *
user_db = [{'id': '34638', 'email': '34638@novasbe.pt', 'password': 'mojalaska'},
{'id': '34646', 'email': '34646@novasbe.pt', 'password': 'mrkremlin'}]
email_input = '33333@novasbe.pt'
password_input = 'ninochka'
def login(email_input, password_input):
counter = 0
for user in user_db:
if user['email'] == email_input and user['password'] == password_input:
return print('You succesfully logged in!')
else:
counter += 1
if counter == len(user_db):
return print('The email or password are not correct.')
def register(email_input, password_input, password_rep_input):
counter = 0
for user in user_db:
if user['email'] == email_input:
return print('This email is already registered.')
else:
counter += 1
if counter == len(user_db):
if password_input != password_rep_input:
return print('The passwords do not match!')
else:
user_db.append(
{'id': email_input[0:5], 'email': email_input, 'password': password_input})
return print('You successfully registered!')
register(email_input, password_input, password_input)
login(email_input, password_input)
votes = [{'id': 1, 'election_id': 1, 'user_id': 44444,
'option': 'Stefan', 'timestamp': time.time()}]
elections = [1]
options = ['Lukas', 'Stefan', 'Andrew']
allowed_voters = ['11111', '22222', '33333', '44444', '55555', '66666']
def cast_ballot(email, option, election):
if election in elections:
if email[0:5] in allowed_voters:
if option in options:
max_id = 0
for vote in votes:
if vote['id'] > max_id:
max_id = vote['id']
votes.append({'id': (max_id+1), 'election_id': election,
'user_id': email[0:5], 'option': option, 'timestamp': time.time()})
return print('Vote successfully transmitted!')
else:
return print('Invalid option!')
else:
return print('You are not allowed to vote in this election.')
else:
return print('This election is either closed or does not exist.')
cast_ballot(email_input, 'Lukas', 1)
new_hash = sha256(('34638'+'Allagi'))
print(new_hash)
new_hash = sha256(('34646'+'Allagi'))
print(new_hash)
new_hash = sha256(('34638'+'Allagi'))
print(new_hash)