0
我正在寫一個python腳本(在python3.4),它散列密碼,另一個腳本登錄用戶Python的登錄程序,用bcrypt
該散列密碼之一:
import bcrypt
password1 = input("pass: ")
password=b"password1"
salt = bcrypt.gensalt()
hashed = bcrypt.hashpw(password, salt)
f=open("passwd.txt","w")
print(hashed,file=f)
f.close()
f1=open("salty.txt","w")
print(salt,file=f1)
f1.close()
if bcrypt.hashpw(password, hashed) == hashed:
print("It Matches")
else:
print("It Does not Match")
另:
import bcrypt
password1 = input("pass: ")
password=b"password1"
f=open("passwd.txt","r")
for i in f:
hashed1=i
f.close()
hashed=b"hashed1"
f1=open("salty.txt","r")
for j in f1:
salt=j
f1.close()
if bcrypt.hashpw(password, hashed) == hashed:
print("It Matches")
else:
print("It Does not Match)
,如果我嘗試使用第二個輸入密碼,並將它與壽另一方面,它告訴我:
ValueError: Invalid salt
那麼你會怎麼做soxnd部分? –
請參閱我的回答,我敢肯定你錯誤地試圖將Unicode轉換爲字節串 –