Python Forum
Basic python login system
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic python login system
#1
So I tried creating a basic login system in python since im just trying it to get a grasp of the language. Im using a txt file to save multiple usernames and passwords in it, while also making use of the tkinter library for a GUI. The user and password are always stored respectively above and below each other. When I got to the stage where I started coding the comparison between an input and the stored user/password i ran into the issue that for some reason when comparing the 2 strings in an if condition they never fit together. Even when I printed the 2 strings just before the condition and the console confirmed they were the same they never change the condition to true.

Maybe its just me thats missing some obvious stuff but I hope someone can give me a plausible answer for this.

from tkinter import *
import time


def getEntryInput():

    Input_User = USER.get()
    Input_Pass = PASS.get()

    UserList = open("User.txt", "r")

    RegisteredUsernames = UserList.readlines()  
    a = 0

    for x in RegisteredUsernames: 

        if Input_User == x:
            
            if Input_Pass == RegisteredUsernames[(a+1)]:
                SuccessLabel.configure(text="Success")
                break
            else:
                SuccessLabel.configure(text="Wrong")
        else:
            SuccessLabel.configure(text="Wrong")
        a = a + 1    
        

    UserList.close()


def RegNewUser():
    RegWindow = Toplevel()
    RegWindow.geometry("200x200")
    RegWindow.title("Register")

    RegTitleLabel = Label(RegWindow, text="Register new user")
    RegTitleLabel.pack()

    RegUSER = Entry(RegWindow)
    RegPASS = Entry(RegWindow)
    RegUSER.insert(0, "Username")
    RegPASS.insert(0, "Password")
    RegUSER.pack()
    RegPASS.pack()

    

root = Tk()
root.geometry("400x300")
titlelabel = Label(root, text="Please Enter User and Password")
SuccessLabel = Label(root)

LogButton = Button(root, text="Login", command=getEntryInput)
RegButton = Button(root, text="Register new user", command=RegNewUser)


USER = Entry(root)
PASS = Entry(root)
USER.insert(0, "Username")
PASS.insert(0, "Password")







titlelabel.pack()
SuccessLabel.pack()
USER.pack()
PASS.pack()
LogButton.place(x=150, y=100, height=50, width=100)
RegButton.place(x=150, y=150, height=50, width=100)
root.title("Login")
root.mainloop()
Reply


Messages In This Thread
Basic python login system - by Asasiene23 - Oct-19-2020, 05:08 PM
RE: Basic python login system - by deanhystad - Oct-19-2020, 08:04 PM

Forum Jump:

User Panel Messages

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