Discuss / Python / 作业

作业

Topic source

月半意

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

第一题

import hashlib
def login(user, password):
    md5 = hashlib.md5()
    md5.update(password.encode('utf-8'))
    pd = md5.hexdigest()
    for key,value in db.items():
        if (key == user) & (value == pd):
            return True
    return False

第二题

db = {
    'michael': User('michael', '123456'),
    'bob': User('bob', 'abc999'),
    'alice': User('alice', 'alice2008')
}

def login(username, password):
    user = db[username]
    password = password + user.salt
    return user.password == get_md5(password)

  • 1

Reply