#coding:utf-8
#定义md5生成函数
def md5(object):
import hashlib
md5=hashlib.md5()
md5.update(object)
return md5.hexdigest()
#模拟注册账号
zhdb={}
def register_user(user,passwd):
if user not in zhdb.keys():
zhdb[user]=md5(user+passwd+'abc')
print 'account register success!'
else:
print 'account already exists!'
#模拟登录
def login_user(user,passwd):
if user in zhdb.keys():
if zhdb[user] == md5(user+passwd+'abc'):
print 'login success!'
else:
print 'password errer!'
else:
print 'accout not exit'
#模拟创建及登录
if __name__ == '__main__':
register_user('tom','123456')
register_user('jack','123456')
register_user('jack','123456')
login_user('tom','123456')
login_user('tom','11111')
login_user('aaa','dfs')
阅读(1765) | 评论(0) | 转发(0) |