簡體   English   中英

在Python中使用Bcrypt哈希密碼時出錯

[英]Getting error while hashing password using Bcrypt in Python

在Python中使用Bcrypt散列痛苦文本密碼時出現錯誤。 我在下面提供錯誤。

Traceback (most recent call last):
  File "hash.py", line 3, in <module>
    hashed = hashpw(plaintext_password, gensalt(log_rounds=13))
TypeError: gensalt() got an unexpected keyword argument 'log_rounds'

我的代碼如下。

from bcrypt import hashpw, gensalt
plaintext_password = 'subhra123@'
hashed = hashpw(plaintext_password, gensalt(log_rounds=13))
print hashed

在這里,我需要對我的密碼進行哈希處理。

您的錯誤來自log_rounds ,您只需使用數字即可。 這是一個例子:

hashed = hashpw(plaintext_password, gensalt(13))

從官方文檔:

可調工作因數bcrypt的功能之一是可調對數工作因數。 要調整工作因子,只需將所需的回合數傳遞給bcrypt.gensalt(rounds = 12),默認為12):

工作演示:

import bcrypt
password = b"super secret password"
# Hash a password for the first time, with a certain number of rounds
hashed = bcrypt.hashpw(password, bcrypt.gensalt(14))
# Check that a unhashed password matches one that has previously been
#   hashed
if bcrypt.hashpw(password, hashed) == hashed:
    print("It Matches!")
else:
    print("It Does not Match :(")

是文檔的鏈接,其中指定了如何使用它。

希望這可以幫助!

我想讓您使用gensalt(13)gensalt(rounds=13)代替gensalt(log_rounds=13)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM