English 中文(简体)
储存和检索邮局的过时密码
原标题:storing and retrieving hashed password in postgres

我正在观看快车道学课程,该课程将数据库从凯科特转换为PogreSQL,然后产生一个信号。 它以前曾工作过,但现在有错误,如下所示:

return bcode.checkpw (password=password_byte_enc, hashed_password=hashed_password) 类型 错误:标语为“密码”的论点不能改为PyBytes

我认为,这是关于错误的法典:

def get_password_hash(password):
    # return bcrypt_context.hash(password)
    pwd_bytes = password.encode( utf-8 )
    salt = bcrypt.gensalt()
    hashed_password = bcrypt.hashpw(password=pwd_bytes, salt=salt)
    return hashed_password


def verify_password(plain_password, hashed_password):
    password_byte_enc = plain_password.encode( utf-8 )
    return bcrypt.checkpw(password=password_byte_enc, hashed_password=hashed_password)

The entirity of the auth.py file is here

This is where I input the username and password to generate a token but it gets an error: username and password input

最佳回答

SOLVED after hashing, using the decode property is needed to store correctly the hash password in the postgres database

def get_password_hash(password):
    pwd_bytes = password.encode( utf-8 )
    salt = bcrypt.gensalt()
    hashed_password = bcrypt.hashpw(password=pwd_bytes, salt=salt)
    string_password = hashed_password.decode( utf8 )
    return string_password


def verify_password(plain_password, hashed_password):
    password_byte_enc = plain_password.encode( utf-8 )
    hashed_password = hashed_password.encode( utf-8 )
    return bcrypt.checkpw(password_byte_enc, hashed_password)

如果任何其他人能找到更好的解决办法,那么,它就会为之敞开大门。

问题回答

暂无回答




相关问题
摘录数据

我如何将Excel板的数据输入我的Django应用? I m将PosgreSQL数据库作为数据库。

Postgres dump of only parts of tables for a dev snapshot

On production our database is a few hundred gigabytes in size. For development and testing, we need to create snapshots of this database that are functionally equivalent, but which are only 10 or 20 ...

How to join attributes in sql select statement?

I want to join few attributes in select statement as one for example select id, (name + + surname + + age) as info from users this doesn t work, how to do it? I m using postgreSQL.

What text encoding to use?

I need to setup my PostgreSQL DB s text encoding to handle non-American English characters that you d find showing up in languages such as German, Spanish, and French. What character encoding should ...

SQL LIKE condition to check for integer?

I am using a set of SQL LIKE conditions to go through the alphabet and list all items beginning with the appropriate letter, e.g. to get all books where the title starts with the letter "A": SELECT * ...

热门标签