#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by TaoYuan on 2017/12/15 0015.
# @Link    : http://blog.csdn.net/lftaoyuan
# Github   : https://github.com/seeways
# @Remark  : Python学习群：315857408
# 根据用户输入的口令，计算出存储在数据库中的MD5口令
import hashlib

db = {
    'michael': 'e10adc3949ba59abbe56e057f20f883e',
    'bob': '878ef96e86145580c38c87f0410ad153',
    'alice': '99b1c2188db85afee403b1536010c2c9'
}


def calc_md5(password):
    return hashlib.md5(password.encode('utf-8')).hexdigest()


def login(user, password):
    if db[user] == calc_md5(password):
        return True
    else:
        return False


# 测试:
assert login('michael', '123456')
assert login('bob', 'abc999')
assert login('alice', 'alice2008')
assert not login('michael', '1234567')
assert not login('bob', '123456')
assert not login('alice', 'Alice2008')
print('ok')

7bec488a1562f3d47d9d6ad26f6af20075d18d6b
<mask token>


def calc_md5(password):
    return hashlib.md5(password.encode('utf-8')).hexdigest()


def login(user, password):
    if db[user] == calc_md5(password):
        return True
    else:
        return False


<mask token>

<mask token>


def calc_md5(password):
    return hashlib.md5(password.encode('utf-8')).hexdigest()


def login(user, password):
    if db[user] == calc_md5(password):
        return True
    else:
        return False


assert login('michael', '123456')
assert login('bob', 'abc999')
assert login('alice', 'alice2008')
assert not login('michael', '1234567')
assert not login('bob', '123456')
assert not login('alice', 'Alice2008')
print('ok')

<mask token>
db = {'michael': 'e10adc3949ba59abbe56e057f20f883e', 'bob':
    '878ef96e86145580c38c87f0410ad153', 'alice':
    '99b1c2188db85afee403b1536010c2c9'}


def calc_md5(password):
    return hashlib.md5(password.encode('utf-8')).hexdigest()


def login(user, password):
    if db[user] == calc_md5(password):
        return True
    else:
        return False


assert login('michael', '123456')
assert login('bob', 'abc999')
assert login('alice', 'alice2008')
assert not login('michael', '1234567')
assert not login('bob', '123456')
assert not login('alice', 'Alice2008')
print('ok')

import hashlib
db = {'michael': 'e10adc3949ba59abbe56e057f20f883e', 'bob':
    '878ef96e86145580c38c87f0410ad153', 'alice':
    '99b1c2188db85afee403b1536010c2c9'}


def calc_md5(password):
    return hashlib.md5(password.encode('utf-8')).hexdigest()


def login(user, password):
    if db[user] == calc_md5(password):
        return True
    else:
        return False


assert login('michael', '123456')
assert login('bob', 'abc999')
assert login('alice', 'alice2008')
assert not login('michael', '1234567')
assert not login('bob', '123456')
assert not login('alice', 'Alice2008')
print('ok')

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by TaoYuan on 2017/12/15 0015.
# @Link    : http://blog.csdn.net/lftaoyuan
# Github   : https://github.com/seeways
# @Remark  : Python学习群：315857408
# 根据用户输入的口令，计算出存储在数据库中的MD5口令
import hashlib

db = {
    'michael': 'e10adc3949ba59abbe56e057f20f883e',
    'bob': '878ef96e86145580c38c87f0410ad153',
    'alice': '99b1c2188db85afee403b1536010c2c9'
}


def calc_md5(password):
    return hashlib.md5(password.encode('utf-8')).hexdigest()


def login(user, password):
    if db[user] == calc_md5(password):
        return True
    else:
        return False


# 测试:
assert login('michael', '123456')
assert login('bob', 'abc999')
assert login('alice', 'alice2008')
assert not login('michael', '1234567')
assert not login('bob', '123456')
assert not login('alice', 'Alice2008')
print('ok')
