skip to Main Content

So i am working on a program that is and I am stuck.
I have a login and signup system that saves new signups in a mysql database.
At the start of the program I take the passwords and names and put them together in a tuple.
Then i put that tuple in a list.
If i wanna login it cant check a tuple in that list.
Here is my code:
Login:

def login():
    userKnown = input("Hallo, heeft u al een account? y/n ")

    if userKnown == "y":
        user = input("username: ")
        passw = input("password: ")
        userjoin = (user,passw)
        if userjoin in bigdata:
            print("login succesful")
        else:
            print("try again")
   

UploadData:

def uploadData():
    print("Bezig met uploaden.")
    mycursor.execute("SELECT name, password FROM userData")
    data = mycursor.fetchall()
    bigdata.append(data)
    print("Upload worked. n")

I hope someone can help me.

A fix to the login system.

3

Answers


  1. Chosen as BEST ANSWER

    I solved it thanks to Georg Richter.

    I used the Where function in select and that worked

    Here is the code:

    def login():
        userKnown = input("Hallo, heeft u al een account? y/n ")
    
        if userKnown == "y":
            user = input("username: ")
            passw = input("password: ")
            userB = (user, passw)
            query = 'SELECT name, password FROM userData WHERE name =%s'
            name = (user,)
            mycursor.execute(query, name)
            userA = mycursor.fetchone()
            print(userA)
            if userA == userB:
                print("succes")
            else:
                print("failed")
    

  2. I think the error is that bigdata does not exist into your login function.
    Try this: def login(bigdata) and call the function in this way: login(bigdata)

    Login or Signup to reply.
  3. Try using try block to find the user its easier this way.

    try:
        pass
        #code to search database
    except Exception as e:
        print(e)
    

    SELECT has a WHERE clause where you can specify user and password to optimize your application.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search