I've been learning Python for about 1 - 1 1/2 weeks now and just finished my first small project to help solidify what I've learnt. It's a very basic (bad) login / create account system that I run in PowerShell but just wanted someone feedback and thoughts as to how I'm getting on in regards to how long I've been learning.
import os.path
def app(user_name):
print(user_name)
def create():
exists = os.path.exists("C:/Users/Tom/Desktop/test/login_project/account_info.txt")
if not exists:
f = open("account_info.txt", "w")
f.close()
creating_username = True
creating_password = True
while creating_username:
user_name = input("\nEnter a username: ")
f = open("account_info.txt", "r")
file_contents = f.read()
if f"'{user_name}'" in file_contents:
print("\nUsername already in use.")
else:
creating_username = False
email = input("Enter an e-mail address: ")
while creating_password:
password = input("Enter a password: ")
password_confirm = input("Confirm password: ")
if password == password_confirm:
info_list = [user_name, password, email]
f = open("account_info.txt", "a+")
f.write(f"{info_list}\r\n")
f.close()
print("\nAccount Created.\n")
creating_password = False
choosing()
else:
print("\nPasswords did not match.\n")
def login():
exists = os.path.exists("C:/Users/Tom/Desktop/test/login_project/account_info.txt")
entering_info = True
while entering_info:
user_name = input("\nEnter username: ")
password = input("Enter password: ")
if not exists:
entering_info = False
print("\nError: [0] account(s) found in database\n")
choosing()
else:
f = open("account_info.txt", "r")
file_contents = f.read()
f = open("account_info.txt", "r")
list_ = [char for char in f.readlines() if char != "\n"]
counter_one = 1
counter_two = 1
for i in list_:
if f"'{user_name}'" in i:
break
counter_one += 1
for y in list_:
if f"'{password}'" in y:
break
counter_two += 1
f.close()
if f"'{user_name}'" in file_contents:
if f"'{password}'" in file_contents and counter_one == counter_two:
print("Login Successful")
entering_info = False
app(user_name)
else:
print("\nPassword incorrect.")
else:
print("\nUsername incorrect.")
def choosing():
main_choosing = True
main_choice = ""
print("Please continue to login or create an account.")
print("(Type 'login' to login, or 'create' to create an account).")
print("('exit' to close program)\n")
while main_choosing:
main_choice = input("- ")
if main_choice == "login" or main_choice == "create" or main_choice == "exit":
if main_choice == "login":
main_choosing = False
login()
elif main_choice == "create":
main_choosing = False
create()
else:
print("\nClosing...\nClosed.")
break
else:
print("\nEnter a valid command.\n")
print("\nWelcome.\n")
choosing()