Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python login system help.
Hi there! I am looking for help with a login system in python, It must contain an array and be able to save the details of users when registered. I have tried to use the array in the username part by making sure a number is in the username. I try to run this and it says my username doesn't include this number, even when it does. Im not sure where the fault lies. any help would be greatly appreaciated.

def CheckNumbers(NewUser):#This ensures that the user enters a number in their username
    number = ['0','1','2','3','4','5','6','7','8','9'] #*ARRAY* of numbers stored.
    for i in range(len(number)): #Checks for numbers in variable NewUser
        if number[i] in NewUser:
            print ("Username Accepted")#prints message
            return NewUser

        elif number[i] not in NewUser: #If number from array created is not in input, prints following msg.
            print("Username is not strong enough, include a number!")
            NewUser= input("Please enter a new username. Remember to include a number!") #Asks user to try again.

def LengthChecker(NewPassW): #This function makes sure password is long enough.
    while len(NewPassW) < 8: #Checks if the password length is less the 8
        print("Password is too short, it must be more than 7 characters!")
        NewPassW = input("Please create a new password.") # asks  user to enter password

    print("Password created.")

    return NewPassW #return new variable

def NewU(): #This Function creates new accounts for user
    NewUser= input("Create new username name")#Asks user to create a new username
    NewUser = CheckNumbers(NewUser)#calls function 'checknumbers'
    if NewUser in users: #checks if user is already in direvtory
        print("User already exists please try again.")
    else: #If user is not already in directory
        NewPassW = input("Create New Password") #Asks user to create password
        NewPassW = LengthChecker(NewPassW) #Calls Lengthchecker function with passing parameter NewPassW
        details(NewUser,NewPassW) #calls details function with passing parameter NewUser and NewPassW
        print("Your Account has been created! Welcome", NewUser)

def OldU():#This function is if the user already has an account
    user = input("Enter Your Username") #Asks user to type in their username
    passW = input("Enter Your Password") #Asks user to type in their password

    for line in open("LoginData.txt","r").readlines(): #Opens and reads the text file
        LogData = line.split()
        if user == LogData[0] and passW ==LogData[1]:
            print("Login Successful!")
        else:#if user does not exist
            print("Incorrect username or password.")

def details(NewUser,NewPassW): #This is where all the created usernames and passwords are stored
    Login = open("LoginData.txt","a+") # Creates or opens LoginData.txt file
    Login.write(" ") #Creats a space between username and password
    Login.write(NewPassW)#writes data for new password
    Login.close #files closes

users = {} #User Dictionary
option = "" #Define global variable "Option"

while option != "Q": #Makes sure Q was not the input.

    option = input("Welcome. Do you already have an account? Type 'Y' or 'N'.Type Q for quit ") #Prompt user to type in Y , N or Q

    if option == "Y": #Checks for Y input
        OldU() #goes to OldU Function
    elif option == "N": #Checks for N input
        NewU() # goes to NewU Function
the problem is that you need to check for all digits before declaring username not valid. at the moment it will print "Username is not strong enough, include a number!" and ask for new username immediately id 0 (zero) is not in the name. Also note that asking for new input within the function that checks the name is not correct - as is it will not be preserved once the function execution ends.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 5,346 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  Login and Register system finndude 1 588 Apr-24-2020, 10:05 PM
Last Post: deanhystad
Question Difference between Python's os.system and Perl's system command Agile741 13 1,615 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Login system not working Unknown_Relic 2 634 Nov-05-2019, 12:07 PM
Last Post: buran
  Login System Carbonix 4 1,775 Feb-04-2019, 02:19 PM
Last Post: Larz60+
  Creating a Login System Using Python- HELP tesilstudent112 0 7,530 Dec-08-2017, 07:17 PM
Last Post: tesilstudent112
  Login a Python Web Crawler on a ASP NET (.aspx) website p4t3x 1 4,048 Dec-01-2017, 11:09 AM
Last Post: hshivaraj
  Login System ItsBlueey 1 25,492 Nov-06-2017, 05:24 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

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