Skip to content

Commit 8409e0a

Browse files
committed
Fix db overwrite bug and catch erroneous inputs
1 parent e3a99fc commit 8409e0a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

usrcheck.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,22 @@ def login_init(usrname,pswd,overWrite,quiet,saltSize):
151151
sys.exit()
152152
elif overWrite==True:
153153
# Bug fix for when no usrlist exists but the user asks not to overwrite user list
154-
newFile = True
155-
if os.path.isfile("usrlist") and (input("Do you want to overwrite the existing user list [Y/N]? ").upper() == 'N'):
156-
newFile = False
154+
newFile = False
155+
if not(os.path.isfile("usrlist")):
156+
newFile = True
157+
elif os.path.isfile("usrlist") and (input("Do you want to overwrite the existing user list [y/N]? ").upper() == 'Y'):
158+
newFile = True
157159
while True:
158160
# TODO:
159161
# Seems to me redundant to ask if they want to clear the database when "overwriting" the existing database does
160162
# the same thing.
161163
nUsr=input("Enter the number of users to initialize ('0' Clears the database): ")
162164
try:
163165
nUsr=int(nUsr)
164-
break
166+
if int(nUsr)<0:
167+
print('The value must not be negative.')
168+
else:
169+
break
165170
except ValueError:
166171
pass
167172
if nUsr>0:

0 commit comments

Comments
 (0)