将输入(密码)转换为MD5
问题描述:
嗨,我对此有点新,无法准确找出如何使其工作。将输入(密码)转换为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()
PasswordCreate()
的错误是:
AttributeError: '_hashlib.HASH' object has no attribute 'encode'
答
import hashlib
def PasswordCreate():
user_in = input(str("Please enter a password next to this text"))
password = hashlib.md5()
password.update(user_in.encode("utf-8"))
return password.hexdigest()
PasswordCreate()
只是一个问题,在您的变量。请参阅我的代码user_in
答
就这么简单,我可以把:
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
那么,什么是你的_exact_问题? – yeputons
@yeputons代码不起作用,我将编辑并把问题的错误 – Josh