Mar-08-2018, 11:41 AM
def existingUser():
userID = input("Please enter your username: ")
password =input("Please enter your password: ")
for line in open("database.txt","r").readlines():
loginDetails = line.split()
csv1= csv.reader("database.txt", delimiter = ',')
if userID == loginDetails[0] and password == loginDetails[1]:
print("Welcome "+(userID))
else:
create=input("You do not have an account, would you like to create one?")
if create == "Yes":
newuser()
else:
end()
home= input("Hello" +(userID) + "Would you like to """"
1: enter homework task
2: check your progress""")
if home == "1":
homework()
elif home =="2":
print("Incorrect password")
return False
def newUser():
databasefile = open("database.txt","a")
userID = input("Enter your username")
#this checks the password is valid
incorrectPass= False
while not incorrectPass:
password= (input ("Enter a password between 5 to 8 characters"))
length = len(password)
if len(password) <3 or len(password)> 9:
print("Sorry, password must be between 5-8 characters, your password is only ", length, " characters long")
else:
#setflag for strength test
lowerCase =0
upperCase =0
digitCase=0
for ch in password:
if ch.islower():
lowerCase =1
if ch.isupper():
upperCase= 1
if ch.isdigit():
digitCase= 1
#Strength output
passwordStrength = upperCase + lowerCase + digitCase
if passwordStrength ==1:
print("This is a weak password")
elif passwordStrength==2:
print("This is a medium password")
if passwordStrength ==3:
print("This is a strong password")
incorrectPass= True
FirstAlevel= input("Enter first A-level")
SecondAlevel=input("Enter second A-level")
ThirdAlevel=input("Enter third A-level")
logindata= open("database.txt", "a+")
line= databasefile.write(userID +"," + password + "," + FirstAlevel+ "," + SecondAlevel + "," + "," + ThirdAlevel + "\n")
databasefile.close()
print("Welcome " + (userID) + ", your account has been created, would you now like to..")
login=input("1.Login 2.Quit")
if login == "2":
sys.exit(0)
elif login =="1":
main()
def end():
sys.exit(0)
def main():
#These are the two options available
print("Welcome to MyOnline Homework Diary")
print("-----------------------------------")
signIn = (int(input("""Would you like to...
1: Register
2: Sign In""")))
if signIn == 1 :
newUser()
elif signIn ==2 :
existingUser()
else:
print ("See you later!")
main()
My code is not allowing any users that have already created an account to sign in and I am not sure why as I am using the csv function to split and read the file but the code is not comparing whats in the text file to the data inputted.
