Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login and Register system
#2
You call new_account_1() recursively if the user types in a username that is already in use.

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() # <-- Recursively call again
    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
You are seeing the password asked for twice because you called new_account_1() twice, once from inside start1() and once from inside new_account_1(). If the user entered two invalid usernames the program would ask for a password three times, one each for the invalid usernames and one for the valid username. If the program actually created a user account, it would create accounts for the invalid usernames. What a mess!

I think you will face similar problems with recursively calling start_1()

Recursion is not a good tool for this problem. Looping is a better fit.
username_taken = True
while username_taken:
    new_username_1 = input ("What do you want to set your username as: ") #ask user to input a new username
    username_taken = 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:
        print ("This username is already taken, please try again") #tells you the username has already been taken
This will loop until an unused username is entered. No mater how many times the user enters an invalid password it still only creates one account and only asks for one password
Reply


Messages In This Thread
Login and Register system - by finndude - Apr-24-2020, 02:13 PM
RE: Login and Register system - by deanhystad - Apr-24-2020, 10:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pymodbus Write value to register stsxbel 10 8,189 Aug-18-2022, 01:42 PM
Last Post: DeaD_EyE
  Simple syntax to asynchronously get access to MODBUS register orion67 1 2,853 Jan-22-2022, 12:40 PM
Last Post: orion67
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 2,281 Feb-20-2021, 04:43 AM
Last Post: bowlofred
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,640 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  AttributeError: 'Register' object has no attribute 'bit_7' colt 1 1,999 Dec-12-2019, 09:39 PM
Last Post: micseydel
Question Difference between Python's os.system and Perl's system command Agile741 13 6,840 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Login system not working Unknown_Relic 2 2,281 Nov-05-2019, 12:07 PM
Last Post: buran
  How to implement class register? AlekseyPython 0 1,994 Feb-14-2019, 06:19 AM
Last Post: AlekseyPython
  Login System Carbonix 4 4,436 Feb-04-2019, 02:19 PM
Last Post: Larz60+
  simple register code aocii 2 2,634 Dec-22-2018, 11:15 AM
Last Post: aocii

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020