Apr-24-2020, 02:13 PM
hi,
i have this code
after you have logged in it should take you to the main part of the program which it does most of the time. however when i do the following i get an output i dont wnat:
create account
use a taken username
try a different non taken username set a password
confirm it wrong
choose logon
login correctly
after i do those steps its says
welcome to your account
what do you want to set your passsword as:
after welcome to your account i want it to move on.
ill show you the output
whatever happens before i want it so that when you finally login successfully i want it to move on to what is next in the program. which is just it asking player 2 to login.
thanks
i have this code
def login_1(): #everything below is what will happen when we use the login() command
print ("\n") #adds a line break
print ("-----------------------------------------------------------------") #lines to make it more presentable
print ("\n") #adds a line break
global username_not_to_be_used #globalises the variable so it cn be used elsewhere
global username_1 #globalises the variable so it can be used elsewehere
username_1 = input ("Enter your username: ") #asks for a user to input there username
username_not_to_be_used = username_1 #sets username_not_to_be_used to the same as username_1
file_check_1 = os.path.isfile("E:/Work/School/Computer Science/Python/Code/School Work/User Info/" + username_1 + ".txt") #checks if the file exists
if file_check_1 == False: #if the check returns as false the username dosent exist
print ("That username dosent exist, please start again") #tells you that the username dosent exist
start_1() #runs the start command
if file_check_1 == True: #if the check returns as true it opens the file to check and see what the password is
password_check_1 = open("E:/Work/School/Computer Science/Python/Code/School Work/User Info" + "/" + username_1 + ".txt","r").read() #looking at what is in the file (the password)
password_1 = input ("Enter your password: ") #asks for the user to input there password
if password_check_1 != password_1: #if the password in the file and the password the user typed arent equal
print("You have entered an incorrect password, please start again") #it tells you the passwords dont match
start_1() #runs the start command
elif password_check_1 == password_1: #if the password from the file and the users inputted one do match
print ("Welcome to your account.") #says welcome to your account
print ("\n") #adds a line break
time.sleep(1) #waits one second till the next action
######################################################################################################
def delete_account_1(): #everything below is what will happen when we use the delete_account() command
delete_user_1 = input ("What is the username of the account you would like to delete? ")
delete_account_check_1 = os.path.isfile("E:/Work/School/Computer Science/Python/Code/School Work/User Info/" + delete_user_1 + ".txt") #checks if the file exists
if delete_account_check_1 == False: #if the check returns as false the username dosent exist
print ("That username dosent exist, please start again") #tells you that the username dosent exist
start_1() #runs the start command
if delete_account_check_1 == True: #if the check returns as true it opens the file to check and see what the password is
delete_password_check_1 = open("E:/Work/School/Computer Science/Python/Code/School Work/User Info" + "/" + delete_user_1 + ".txt","r").read() #looking at what is in the file (the password)
delete_password_1 = input ("Enter your password: ") #asks for the user to input there password
if delete_password_check_1 != delete_password_1: #if the password in the file and the password the user typed arent equal
print("You have entered an incorrect password, please start again") #it tells you the passwords dont match
start_1() #runs the start command
elif delete_password_check_1 == delete_password_1: #if the password from the file and the users inputted one do match
confirm_delete_1 = input ("Are you sure you want to delete this account? yes/no ") #asks if you want to delete account
if confirm_delete_1 == "yes": #if yes is inputted
os.remove("E:/Work/School/Computer Science/Python/Code/School Work/User Info" + "/" + delete_user_1 + ".txt") #deletes the file form user info folder
print ("This account has now been deleted! ") #tells you the account has been deleted
print ("-----------------------------------------------------------------") #adds lines to make it more presentable
start_1() #runs the start_2() command
elif confirm_delete_1 == "no": #if no is inputted
print ("Ok we will return to the start") #says it will return to the start
start_1() #runs start_1() command
else: #if anyting else is inputted
print ("That is an invalid input, please start again") #says its an invalid input
start_1()
######################################################################################################
def start_1():#everything below is what will happen we use the start() command
print ("Welcome to FWW login systems:") #says welcome to FWW login systems
time.sleep(1) #adds a 1 second break
user_option_1 = input ("Hello User 1 - Do you want to 'logon' or 'create account' or 'delete account' - please answer with one of those options ") #asks if you have an account
if user_option_1 == "logon": #if the response is yes
print ("\n") #adds a break
print ("Please Login:") #says please login
login_1() #runs login() command
elif user_option_1 == "create account": #if the answer is no
print ("\n") #adds a liine break
print ("Please Register") #says please register
print ("\n") #adds a line break
print ("-----------------------------------------------------------------") #adds lines to make it more presentable
print ("\n") #adds a line break
new_account_1() #runs new_account() command
elif user_option_1 == "delete account": #if the user inputs delete account
delete_account_1() #runs delete account command
else: #if anything else is inputted
print ("That is an invalid input, please try again") #tells you its an invalid input
start_1() #runs the start() command
######################################################################################################
def new_account_1(): #aything below is what will happen when we use new_account() command
new_username_1 = input ("What do you want to set your username as: ") #ask user to input a new username
username_taken_check_1 = os.path.isfile("E:/Work/School/Computer Science/Python/Code/School Work/User Info/" + new_username_1 + ".txt") #checks if the file exists
if username_taken_check_1 == True: #is it returns as true and the file does exist
print ("This username is already taken, please try again") #tells you the username has already been taken
new_account_1() #runs the new_account() command
elif username_taken_check_1 == False: #if it returns as false and the file dosent exist
print ("Okay your new username is, " + new_username_1) #tells them what the new username is
new_password_1 = input ("What do you want to set your password as: ") #asks what they want there password to be
confirm_password_1 = input ("Please confirm your password: ") #asks them to retype/confirm there password
if new_password_1 == confirm_password_1: #checks if the passwords match
user_details_1 = open("E:/Work/School/Computer Science/Python/Code/School Work/User Info" + "/" + new_username_1 + ".txt","w") #creates a new file called "username".txt
user_details_1.write(new_password_1) #writes in the file what the users password is
user_details_1.close() #saves and closes the file
print ("Your passwords match!") #tells you they match
print ("Your account has been created!") #tells you that your account has been created
print ("Please now proceed to the next step") #says to proceed
print ("\n") #adds a line break
print ("-----------------------------------------------------------------") #lines to make it more presentable
print ("\n") #adds a line break
start_1() #runs the start_1() command
else: #if anything else is inputted
print ("You have made an error. Please start again") #tells the user they made and error
start_1() #runs the start() command
######################################################################################################
start_1() #runs the start() commandbasically its a login system.after you have logged in it should take you to the main part of the program which it does most of the time. however when i do the following i get an output i dont wnat:
create account
use a taken username
try a different non taken username set a password
confirm it wrong
choose logon
login correctly
after i do those steps its says
welcome to your account
what do you want to set your passsword as:
after welcome to your account i want it to move on.
ill show you the output
Output:Welcome to FWW login systems:
Hello User 1 - Do you want to 'logon' or 'create account' or 'delete account' - please answer with one of those options create account
Please Register
-----------------------------------------------------------------
What do you want to set your username as: test
This username is already taken, please try again
What do you want to set your username as: tetset
Okay your new username is, tetset
What do you want to set your password as: t
Please confirm your password: g
You have made an error. Please start again
Welcome to FWW login systems:
Hello User 1 - Do you want to 'logon' or 'create account' or 'delete account' - please answer with one of those options logon
Please Login:
-----------------------------------------------------------------
Enter your username: test
Enter your password: test
Welcome to your account.
What do you want to set your password as:when it asked for your passwrod that shouldnt happen,whatever happens before i want it so that when you finally login successfully i want it to move on to what is next in the program. which is just it asking player 2 to login.
thanks
"Only Boring People Get Bored"
