Jump to content

ScribhneoirIldanach

New Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by ScribhneoirIldanach

  1. The code below for a log-in window I've made always gets a "SyntaxError: invalid syntax" message whenever I try to run it in Python after I tried to fix a indentation error in the code. What am I doing wrong and why do I keep getting this error? #import packages import sys, time import string, random username = "" password = "" print("Welcome...") print("\nWould you like to:") #print the main menu print("\nA) Login") print("B) Create an account") print("V) View accounts") print("C) Quit") #enter the menu choice i = input("\nChoose [a/b/c]: ") if (i == "a" or i == "A"): #If the login is selected then it must check against the file #if username and password is found and display the messages accordingly print("\nLOGIN:") print("----------------------------------------------------------") username = input("\nEnter username: ") password = input("Enter password: ") f = open("accounts.txt", 'r') info = f.read() info = info.split() if username in info: index = info.index(username) + 1 usr_pass = info[index] if usr_pass == password: print("\nYou have successfully logged in.") time.sleep(1) sys.exit() else: print("\nPassword incorrect. Please try again.") else: print("No record of this user. Please register.") if (i == "b" or i == "B"): #New account creation with both the option #random password and manual password creation print("\nCREATING NEW ACCOUNT:") print("-------------------------------------------------------") username = input("\nEnter username: ") f = open("accounts.txt", 'r') info = f.read() if username in info: print("\nUsername unavailable. Please try again.") f.close() else: print("\nWould you like to:") print("\nA) Create your own password") print("B) Randomly generate a password") i = input("\nChoose [a/b]: ") if (i == "a" or i == "A"): password = input("\nEnter password: ") with open("accounts.txt", "a") as f: combo = username + " " + password f.write(combo + "\n") f.close() print("\nYour account has been created.") print("You can now log in.") else: print("\nLet's create a unique password for you...") useDigits = input("Would you like your password to include numbers? [y]/n: ") if useDigits.lower() == "n": use_digits = False else: use_digits = True usePunctuation = input("\nWhat about symbols? [y]/n: ") if usePunctuation.lower() == "n": use_punctuation = False else: use_punctuation = True passwordLength = input("\nLength of the password [10]: ") if passwordLength == "": password_length = 10 else: password_length = int(passwordLength) letters = string.ascii_letters digits = string.digits punctuation = string.punctuation symbols = letters if use_digits: symbols += digits if use_punctuation: symbols += punctuation password = "".join(random.choice(symbols) for i in range(password_length)) print("\nYour new generated password is: " + str(password)) with open("accounts.txt", "a") as f: combo = username + " " + password f.write(combo + "\n") f.close() print("\nYour account has been created.") print("You can now log in.") if (i == "c" or i == "C"): #option c exits the program after a delay of 2 seconds print("\nExiting program...") time.sleep(2) sys.exit() if (i == "v" or i == "V"): #open the file in read mode and read line by line and display on #screen. This will display all the account details from the file. print() f = open("accounts.txt") for line in f: print(line) f.close #Program starts here
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.