Discuss / Python / exercise 3(hashlib)

exercise 3(hashlib)

Topic source

叫我_小军

#1 Created at ... [Delete] [Delete and Lock User]

-根据用户输入的登录名和口令模拟用户注册,计算更安全的MD5- import hashlib db = {} def register(username,password): md5 = hashlib.md5() get_mad5 = md5.update(str(password) + str(username) + 'the-Salt'.encode('utf-8')).hexdigest() db[username] = get_mad5 return

-然后,根据修改后的MD5算法实现用户登录的验证- def login(username, password): md5 = hashlib.md5() md5.update(str(password) + str(username) + 'the-Salt'.encode('utf-8')) md5_password = md5.hexdigest() return print(db[username] == md5_password)

-验证- register('michael',123456) login('michael',123456)

前面两道练习题都顺利执行了,但不知道这道题为什么会出错: get_mad5 = md5.update(password + 'the-Salt'.encode('utf-8')).hexdigest() TypeError: Can't convert 'bytes' object to str implicitly

希望大神能够告知!

yunhang_14385

#2 Created at ... [Delete] [Delete and Lock User]

update函数没有返回值

import hashlib

md5 = hashlib.md5() md5.update(('password'+'the-Salt').encode('utf-8')) print(md5.hexdigest())

str(password) + str(username) + 'the-Salt'这一部分是一个整体,需要加一个括号


  • 1

Reply