所以我用QtDesigner创建了一个注册窗口,该窗口将用户的信息存储在DataFrame中。 但是对于密码,我希望它被散列。 现在,当程序到达 HPW Line 时,将引发此错误:
File "c:/Users/pc/Desktop/qt_test_auth/su_win.py", line 225, in confirmFunc
HPW = hashlib.sha512(PW.encode('utf-8') + salt).hexdigest()
TypeError: can't concat str to bytes
我尝试自行调试,但无法。 非常感谢你!
-头-
import sys
import hashlib, uuid
from PyQt5 import QtCore, QtGui, QtWidgets
import pandas as pd
-身体-
class sign_up(QtWidgets.QMainWindow):
def __init__(self):...
def setupUi(self, sign_up):...
def cancelFunc(self):...
def clearFunc(self):...
def confirmLockOn(self):...
def confirmLockOff(self):...
**def confirmFunc(self):**
FN = self.FN_lineEdit.text()
LN = self.LN_lineEdit.text()
EA = self.EA_lineEdit.text()
CEA = self.CEA_lineEdit.text()
UN = self.SU_UN_lineEdit.text()
PW = self.SU_PW_lineEdit.text()
CPW = self.SU_CPW_lineEdit.text()
self.buttonReply = QtWidgets.QMessageBox.question(
self,
'ConfirmInputs()',
"First name : %s \nLast name: %s \nEmail Adress: %s \nEmail confirmation: %s \nUsername: %s \nPassword: %s \nPassword confirmation: %s" %(FN, LN, EA, CEA, UN, PW, CPW),
QtWidgets.QMessageBox.Yes| QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
if self.buttonReply == QtWidgets.QMessageBox.Yes :
salt = uuid.uuid4().hex
HPW = hashlib.sha512(PW.encode('utf-8') + salt).hexdigest()
userinput = {}
userinput['First name'] = [FN]
userinput['Last name'] = [LN]
userinput['Email'] = [EA]
userinput['Username'] = [UN]
userinput['Hashed Password']=[HPW]
df = pd.DataFrame(data = userinput, columns= ['First name', 'Last name', 'Email Adress', 'Username', 'Hashed Password'])
print(df)
else:
self.close()
self.show()
def main():
app = QtWidgets.QApplication(sys.argv)
main = sign_up()
main.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
答案 0 :(得分:0)
问题很简单:salt是docs所指示的字符串:
UUID.hex
UUID为32个字符的十六进制字符串。
因此,如果要连接,必须将其转换为字节,如下所示:
HPW = hashlib.sha512(PW.encode('utf-8') + salt.encode('utf-8')).hexdigest()