1
+ def configRead ():
2
+ import configparser
3
+ config = configparser .ConfigParser ()
4
+ config .read ('config.ini' )
5
+ try :
6
+ quiet = config ['Config' ]['quiet' ]
7
+ quiet = quiet .lower () in ("true" )
8
+ except KeyError :
9
+ quiet = False
10
+ try :
11
+ alg = config ['Config' ]['alg' ]
12
+ alg = str (quiet ).lower ()
13
+ except KeyError :
14
+ print ("ERROR: Algorithm not defined. Reverting to SHA256" )
15
+ alg = 'sha256'
16
+ try :
17
+ saltSize = config ['Salt' ]['saltSize' ]
18
+ saltSize = int (saltSize )
19
+ except KeyError :
20
+ saltSize = 8
21
+ print ("ERROR: saltSize not defined or not integer. Reverting to 8" )
22
+ return quiet ,alg ,saltSize
23
+
24
+ def salter (pswd ,saltsize ):
25
+ import string
26
+ import secrets
27
+ pass
28
+
1
29
def init_usrs (nUsr ):
2
30
import hashlib
3
31
usrlist = []
@@ -26,11 +54,14 @@ def save_users(usrlist,overWrite):
26
54
saveFile = open ("usrlist" , "w" )
27
55
else :
28
56
saveFile = open ("usrlist" , "a" )
29
- for x in range (len (usrlist )):
30
- if (x - 2 )< len (usrlist ):
31
- saveFile .write (str (usrlist [x ][0 ])+ "," + str (usrlist [x ][1 ])+ "," )
32
- else :
33
- saveFile .write (str (usrlist [x ][0 ])+ "," + str (usrlist [x ][1 ]))
57
+ if len (usrlist )> 0 :
58
+ for x in range (len (usrlist )):
59
+ if (x - 2 )< len (usrlist ):
60
+ saveFile .write (str (usrlist [x ][0 ])+ "," + str (usrlist [x ][1 ])+ "," )
61
+ else :
62
+ saveFile .write (str (usrlist [x ][0 ])+ "," + str (usrlist [x ][1 ]))
63
+ else :
64
+ saveFile .write ('' )
34
65
saveFile .close ()
35
66
36
67
def usr_check (usrn ,pswd ,usrlist ):
@@ -78,7 +109,7 @@ def login_init(usrname,pswd,overWrite,quiet):
78
109
else :
79
110
newFile = False
80
111
while True :
81
- nUsr = input ("Enter the number of users to initialize: " )
112
+ nUsr = input ("Enter the number of users to initialize ('0' Clears the database) : " )
82
113
try :
83
114
nUsr = int (nUsr )
84
115
break
@@ -87,43 +118,47 @@ def login_init(usrname,pswd,overWrite,quiet):
87
118
if nUsr > 0 :
88
119
usrlist = init_usrs (nUsr )
89
120
save_users (usrlist ,newFile )
121
+ elif nUsr == 0 :
122
+ save_users ([],True )
90
123
else :
91
124
usrlist = load_users ()
92
125
Ufound ,Pfound = usr_check (usrname ,pswd ,usrlist )
93
126
loginSt = login_status (Ufound ,Pfound ,quiet )
94
127
return loginSt
95
128
96
129
97
- def Auth_test ():
130
+ def Auth_test (quiet ):
98
131
import os
132
+ configRead ()
99
133
try :
100
134
print ("[Authentication Test]" .center (os .get_terminal_size ().columns ))
101
135
except OSError :
102
136
print ("[Authentication Test]" )
103
137
usr = input ("Input username: " )
104
138
pswd = input ("Input password: " )
105
- if input ("Enable quiet mode? [y/N]" ).upper () == "Y" :
106
- quiet = True
107
- else :
108
- quiet = False
139
+ # if input("Enable quiet mode? [y/N]").upper() == "Y":
140
+ # quiet=True
141
+ # else:
142
+ # quiet=False
109
143
loginSuccess = login_init (usr ,pswd ,False ,quiet )
110
144
print ("Login success status:" , loginSuccess )
111
145
112
146
def main_menu ():
147
+ quiet ,alg ,saltSize = configRead ()
113
148
print ("\n --- Main Menu ---" )
114
149
print ("0. Initialize user accounts" )
115
150
print ("1. Test Authentication" )
116
151
print ("2. Exit" )
117
152
choice = input ("Enter your choice: " )
118
153
if choice == '0' :
119
- login_init ('' ,'' ,True ,False )
154
+ login_init ('' ,'' ,True ,quiet )
120
155
elif choice == '1' :
121
- Auth_test ()
156
+ Auth_test (quiet )
122
157
elif choice == '2' :
123
158
print ("Exiting program." )
124
159
exit ()
125
160
else :
126
- print ("Invalid choice. Please enter 1 or 2." )
161
+ print ("Invalid choice. Please enter 0, 1 or 2." )
127
162
main_menu ()
128
163
129
164
if __name__ == "__main__" :
0 commit comments