嘿伙计们,我已经使用 bcrypt 和其他方法在 mysql 服务器中存储加密密码几天了。似乎没有任何工作,似乎没有人能解决这个问题。目前使用 fernet 作为 bcrypt 的替代品,但它仍然不起作用。我创建了一个加密类:
class PwdCipher:
def generate_key(self,usr:str):
if os.path.isfile("pass_keys/"+usr+".key"):
return 1
else:
key = Fernet.generate_key()
with open("pass_keys/"+usr+".key","wb") as key_file:
key_file.write(key)
return 0
def load_key(self,usr:str):
if os.path.isfile("pass_keys/"+usr+".key"):
return open("pass_keys/"+usr+".key","rb").read()
else:
return 1
def encrypt(self,usr:str,pwd:str):
if self.generate_key(usr) == 0:
key = self.load_key(usr)
encoded_pwd = pwd.encode()
f = Fernet(key)
return f.encrypt(encoded_pwd)
else:
return 1
def decrypt(self,usr:str,encrypted_pwd):
if self.load_key(usr) == 1:
return 1
else:
key = self.load_key(usr)
f = Fernet(key)
encoded_pwd = encrypted_pwd.encode()
decrypted_msg = f.decrypt(encoded_pwd)
print(decrypted_msg)
这被称为:
def root_task_handler(self,task):
if task[0][2:] == "create_user":
usr = task[1]
pwd = task[2]
email = task[3][:-1]
encrypted_pwd = self.pwd_cipher.encrypt(usr,pwd)
if encrypted_pwd == 1:
print("[" + str(datetime.datetime.now()) + " - INFO] " + "USR KEY ALREADY EXISTS ...ABORTING " + usr)
else:
if self.query.create_user(usr,encrypted_pwd,email) == 0:
print("[" + str(datetime.datetime.now()) + " - INFO] " + "ROOT USER CREATED ACCOUNT " + usr)
elif task[0][2:] == "delete_user":
usr = task[1]
pwd = task[2][:-1]
encrypted_pwd = self.query.get_password(usr)
db_pwd = self.pwd_cipher.decrypt(usr,encrypted_pwd)
在这一点上,我乞求一个答案。如果您知道任何事情,请告诉我!我会很感激的:)