Why can't bcrypt find 'checkpw'

29 Views Asked by At

I'm writing a program with Python. It has a login and I want to use bcrypt but it's not working. Instead, it shows the following error message:

AttributeError: type object 'bcrypt' has no attribute 'checkpw'. Did you mean: 'checksum'?

It also showed an error message when I used bcrypt.hashpw instead of bcrypt.hash. So I changed that.

Here is my code:

    import bcrypt

    db.base.metadata.create_all(db.engine)
    my_session = Session(bind=engine)


    def login():
        #password = getpass("Please enter your password: ").strip()
        password = pwinput.pwinput(mask='*')
        hashed_password = bcrypt.hash(password.encode('utf-8'))
        check_user_exists(username, password, hashed_password)


    def check_user_exists(username, password, hashed_password):
        db_user = my_session.query(User).filter_by(username=username).first()
        if db_user is None:
            user = User(username=username, password=hashed_password)
            my_session.add(user)
            my_session.commit()
            print("A new User " + username + " has been registered")
        else:
            if not bcrypt.checkpw(password.encode('utf-8'), hashed_password):
                print("Wrong password")
                login()
        print("successful login")

I reinstalled bcrypt, I reinstalled anaconda3, I checked if the folder was named bcrypt.py

0

There are 0 best solutions below