首页 > 其他 > 详细

登陆加密小程序

时间:2017-01-08 20:14:14      阅读:218      评论:0      收藏:0      [点我收藏+]

自己想的注册登录小程序测试,使用md5加密存储用户填写的密码信息。登陆三次密码错误后退出

#!/usr/bin/env python
#_*_ coding:utf-8 _*_

import hashlib

def zhuce():

    username = raw_input("please input your username")
    password = raw_input(please input your password)
    hash = hashlib.md5()
    hash.update(password)
    with open(info.txt,r+) as fd:
        fd.write(username)
        fd.write(\t)
        fd.write(hash.hexdigest())
        fd.write(\n)
    print "注册成功"

def login(user,passwd):
    with open(info.txt) as fd:
        for line in fd:
            if user == line.strip(\n).split()[0] and passwd == line.strip(\n).split()[1]:
                return True
            else:
                return False

def menu():
    memu = ‘‘‘
    1 注册
    2 登陆
    ‘‘‘
    print memu

count = 0
retry = 3

while count < retry:
    menu()
    choice = raw_input(Please input your choice!)
    if choice == 1:
        zhuce()
    if choice == 2:
        user = raw_input(请输入用户名:)
        passwd = raw_input(请输入密码:)
        hash1 = hashlib.md5()
        hash1.update(passwd)
        password = hash1.hexdigest()
        result = login(user,password)
        if result:
           print success!
            break
        else:
            print error
            count += 1 

 

登陆加密小程序

原文:http://www.cnblogs.com/dachenzi/p/6262536.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!