Home > Blockchain >  Python, Pandas : I want to use pandas with a user login form
Python, Pandas : I want to use pandas with a user login form

Time:06-06

I have make a form with tKinter that has 2 Entries (username, password)

I also have a csv file that contains my user info

I am importing the file like so:

admin_df = pd.read_csv('csv/admins.csv')

I want to get the username and password that the user is going to give me and check if they are in my dataframe

I figured out that I can check for the username like so:

if(df.admin_df[df.admin_df['username'].str.contains(username)].empty)

But I am having trouble with the password I don't want to check the whole dataframe for the given password, I want to get the outcome from when I "found" the username and check if the given password is the same as I have in the dataframe

I have tried some things:

where "username" is the given username and "password" is the given password

1) user_df[df.user_df['username'].str.contains(username)]['password'].str.match(password)

2) user_df[df.user_df['username'].str.contains(username)]['password'].to_string == "password"

1) user_df[df.user_df['username'].str.contains(username)]['password'].str.match(password).any()

Problems (as I understand them): 1)It is not really a boolean 2)It is not really a string 3)It did not work (I don't know why)

CodePudding user response:

Here are some fixes. This line will get you the row with only username and password values for the username specified. Watch out that str.contains() also accepts subset of the string and you don't want that.

user_info = admin_df[['username', 'password']][admin_df['username'] == username]

Then you can check if the password matches using this:

user_password = user_info.password.values[0]
if password == user_password:
    ....

You can now tweak it to your usage with conditions to handle if the user exist or not and so on.

  • Related