Dec-11-2017, 12:26 PM
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 sys import sqlite3 #Program #1 - Main Page : Login or Register #existingUser codes for a user that already has an account def existingUser(): userID = input ( "Please enter your username: " ) password = input ( "Please enter your password: " ) for line in open ( "database.csv" , "r" ).readlines(): loginDetails = line.split() if userID = = loginDetails[ 0 ] and password = = loginDetails[ 0 ]: print ( "Welcome" + userID) return True print ( "Incorrect password" ) existingUser() return False #newUser codes for a user that doesn't already have an account and is making one def newUser(): databasefile = open ( "database.csv" , "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" ) databasefile.write(userID + "," + password + "," + FirstAlevel + "," + SecondAlevel + "," + ThirdAlevel + "," + "/n" ) databasefile.close() sys.exit( 0 ) def main(): #These are the two options available print ( "Welcome to MyOnline Homework Diary" ) print ( "1: register" ) print ( "2: login" ) signIn = ( input ( "Do you have an existing account? Y or N?" )) if signIn = = "N" : newUser() elif signIn = = "Y" : existingUser() main() |
Hi,
I am an A-level student currently designing an online homework tracker as my project for my OCR Computer Science course. I am having problems with the code for my login.
At the moment, I am using a database on excel to store my username and password details and my system for registering a user works fine. However, when I want to login as the user I just registered I cannot find a way to search my database to match the username and password to the one located in the database. Right now, this is my code (above) and it just prints out "Incorrect Password" for every username and password I input.
The database is stored as a .csv file.
Thanks in advance for your help
Kezia