Discuss / Python / 作业

作业

Topic source

南墙小生

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

def get_md5(s):
    md5 = hashlib.md5()
    md5.update(s.encode('utf-8'))
    return md5.hexdigest()

db = {}

def register(username, password):
    db[username] = get_md5(password + username + 'the-Salt')

def login(username, password):
    password_md5 = get_md5(password + username + 'the-Salt')
    return username in db and db[username] == password_md5

register('michael', '123456')
print(login('michael', '123456'))

  • 1

Reply