Discuss / Python / 练习1

练习1

Topic source
# _*_ coding: utf-8 _*_
import hashlib
db = {
    'michael': 'e10adc3949ba59abbe56e057f20f883e',
    'bob': '878ef96e86145580c38c87f0410ad153',
    'alice': '99b1c2188db85afee403b1536010c2c9'
}

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

def login():
    while True:
        user = input('welcome to login to the website, please input your username:')
        password = input('input your password to login in:')
        #pass = calc_md5(password)
        if calc_md5(password) == db[user]:
            print('you are login in, welcome!')
                return True
        else:
            print('wrong password, try again')
                return False

if __name__ == '__main__':
    login()    

  • 1

Reply