0
    #imports

import os
import tkinter
import random
import sys
import datetime
import cryptography
import base64
import os
import csv
import pandas

#datetime

x = datetime.datetime.now()
thedate=(x.strftime("%x"))

#tkinter

from tkinter import messagebox
root = tkinter.Tk()
root.withdraw()

#login or signup

login = messagebox.askquestion('Login','Do you already have an account with us?')
if login == 'yes': #login
    messagebox.showinfo('Login','Please enter your username.')
    username_ask=input("Please enter your username.")
    messagebox.showinfo('Login','Please enter your password for account: '+username_ask)
    password_ask=input("Enter password.")
    #password encrytion checker
    from cryptography.hazmat.backends import default_backend
    from cryptography.hazmat.primitives import hashes
    from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
    password_ask_decrypt = (password_ask)
    password_ask_encrypt = (password_ask_decrypt).encode()
    salt = b'\xe2\xaf\xbc:\xdd'
    kdf = PBKDF2HMAC(
        algorithm=hashes.SHA256(),
        length=32,
        salt=salt,
        iterations=100000,
        backend=default_backend()
    )
    logintoken = base64.urlsafe_b64encode(kdf.derive(password_ask_encrypt))

logincorrect = False
while logincorrect == False:
    data=[ ]
    with open('database.csv')as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            data.append(row)
    print(data)
    print(logintoken)

    col0 = [x[0] for x in data]
    col1 = [x[1] for x in data]
    print(col0)

    if username_ask in col0:

        for k in range(0, len(col0)):
            if col0[k] == username_ask and col1[k] == logintoken:
                messagebox.showinfo('Welcome','You succesfully logged in to your account: '+username_ask)
                logincorrect == True
                sys.exit()
            else:
                messagebox.showerror('Incorrect','Your credientials is incorrect, please try again.')
                sys.exit()

    else:
        messagebox.showerror('Invalid','Your credentials were not found, please try again')
        sys.exit()

Whenever I run this code and type in my correct username and password, it tells its not, but why?

The program looks through a csv file to find the username and password given by the user.

The password is encrypted.

However, when it compares it, it says its incorrect.

When I remove the password comparison, it works fine.

Here is the csv. CSV file

Also, the credentials are test for username and test for password.

0 Answers0