forked from KanishkM08/Sudo-Solver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.py
159 lines (115 loc) · 4.35 KB
/
driver.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
import os
import re
import shutil
import sys
import board_prettyprint
import board_solver
import console_user_input
import user_account_control as uac
title_file = "assets/ascii_title.txt"
help_file = "assets/ascii_instructions.txt"
def validate_login(uname, pwd):
if not re.search('(?=.*[a-zA-Z0-9])(?=.*[-+_!@#$%^&*.,?])', pwd): # Reegex for checking password validity
return False, 'Password must contain:\n\
- At least one upper-case character\n\
- At least one lower-case character\n\
- At least one number\n\
- At least one special character'
if len(pwd) < 8:
return False, 'Password must be at least 8 characters long!'
if uname == pwd:
return False, 'Please choose a different password, the username and password should not be the same!'
return True, None
def get_logininfo():
uname = input("Enter a username: ")
if uac.check_existing_user(uname):
print(f"Hello {uname}! Please enter your password.")
while True:
pwd = input('Enter Password: ')
pwd_hash = uac.hash_sha256(pwd)
if pwd_hash == uac.hash_sha256(''):
res = False, None
break
res = uac.login(uname, pwd_hash)
if res[0]:
break
print('Invalid password! Please try again, or press ENTER to sign up / choose a different account.')
else:
print("Welcome new user! Please create a password. (Minimum 8 characters long)")
print('Password must contain:\n\
- At least one upper-case character\n\
- At least one lower-case character\n\
- At least one number\n\
- At least one special character')
while True:
pwd = input('Enter password: ')
validation = validate_login(uname, pwd)
if not validation[0]:
print(validation[1])
continue
pwd_hash = uac.hash_sha256(pwd)
pwd1_hash = uac.hash_sha256(input('Re-enter password: '))
if pwd_hash == pwd1_hash:
break
print('Passwords do not match!')
uac.signup(uname, pwd_hash, hashed=True)
res = uac.login(uname, pwd_hash)
return res
def print_title():
cols, _ = shutil.get_terminal_size()
with open(title_file, encoding="utf-8") as tf:
lines = tf.readlines()
tf.seek(0)
max_length = max([len(l) for l in lines])
if cols < max_length:
os.system(f'mode con: cols={max_length} lines=40')
print(tf.read())
def print_help():
with open(help_file, encoding="utf-8") as hf:
print(hf.read())
input()
def run_cli_solving_sequence():
os.system("cls" if os.name == "nt" else "clear")
board = console_user_input.get_input()
solve_state, solved_board = board_solver.solve(board)
if solve_state:
print("\n\n\n")
print("SOLVED! Here's the solution to the entered board:\n\n\n")
board_prettyprint.prettyprint(solved_board)
return
print("\n\n\n")
print(
"The entered board cannot be solved! This may be because of a repeated"
" number or other invalidity in the entered configuration."
)
return
# def construct_prompt(name, message, choices):
# return [inquirer.List(name, message, choices)]
# def prompt_user(prompt, name):
# return inquirer.prompt(prompt)[name]
if __name__ == "__main__":
try:
print_title()
print("\n\n\n")
help_yn = input("Print help file? (Y/N): ").strip().lower()
if help_yn == "y":
print_help()
while True:
info = get_logininfo()
if info[0]:
break
print(f'\n\nHey {info[1][0]}, welcome to SudoSOLVE! Here are your user details:\n')
print(f'Username: {info[1][0]}\nData folder: {info[1][1]}\n\n')
input('Press ENTER to continue...')
app_mode = "cli"
if app_mode == "cli":
while True:
run_cli_solving_sequence()
solve_another = input('Solve another puzzle? (Y/N): ').strip().lower()
if solve_another == "y":
continue
with open("assets/ascii_thanks.txt", encoding="utf-8") as thxf:
print(thxf.read())
break
except:
sys.exit()