Python 将输入(密码)转换为MD5
嗨,我对这个有点陌生,不知道如何让它工作 这是我目前的代码:Python 将输入(密码)转换为MD5,python,md5,Python,Md5,嗨,我对这个有点陌生,不知道如何让它工作 这是我目前的代码: import hashlib def PasswordCreate(): password = input(str("Please enter a password next to this text")) password = hashlib.md5() password.update(password.encode('utf-8')) return password.hexdigest() Pa
import hashlib
def PasswordCreate():
password = input(str("Please enter a password next to this text"))
password = hashlib.md5()
password.update(password.encode('utf-8'))
return password.hexdigest()
PasswordCreate()
错误是:
AttributeError: '_hashlib.HASH' object has no attribute 'encode'
也许是这样的:
import hashlib
def PasswordCreate():
password = raw_input(str("Please enter a password next to this text: "))
return hashlib.md5(password).hexdigest()
PasswordCreate()
只是变量中的一个问题。请参见我的代码中的
user\u,尽可能简单:
import hashlib
print(hashlib.md5(input().encode()).hexdigest())
你好,乔希,
试试这个代码
import hashlib
def PasswordCreate():
inputVar = input(str("Please enter a password next to this text: "))
password = hashlib.md5()
password.update(inputVar.encode("utf-8"))
return password.hexdigest()
# Create Variable for dipslay encoded value.
displayPass = PasswordCreate()
print "User Password is: ",displayPass
那么,你的确切问题是什么?@yeputons代码不起作用,我会编辑并把错误放在问题中。我使用的是Python 3.5,原始输入不是一件我很确定的事情(至少它不起作用),而且在Python 3.5中,你必须对“东西”进行编码,所以这真的没有帮助。感谢代码现在运行良好,但是它似乎没有输出字符串(我想这样做是为了测试)我如何才能实现这一点?只需将PasswordCreate()
封装在print()
函数中,即print(PasswordCreate())
我也只想澄清一下。如果您没有在代码中使用salt,那么如果安全性很重要,我们强烈建议您使用salt。维基百科有时有很好的解释:)嘿,只是想知道你是否可以点击“接受答案”按钮?这将是非常感谢:)嗨,很抱歉没有接受,它的工作谢谢,没有安全对我来说并不重要,这是一个附带项目
import hashlib
def PasswordCreate():
inputVar = input(str("Please enter a password next to this text: "))
password = hashlib.md5()
password.update(inputVar.encode("utf-8"))
return password.hexdigest()
# Create Variable for dipslay encoded value.
displayPass = PasswordCreate()
print "User Password is: ",displayPass