Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将输入(密码)转换为MD5_Python_Md5 - Fatal编程技术网

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