码迷,mamicode.com
首页 > 其他好文 > 详细

登陆加密小程序

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

标签:strip   write   port   ror   注册   lib   use   bsp   使用   

自己想的注册登录小程序测试,使用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 

 

登陆加密小程序

标签:strip   write   port   ror   注册   lib   use   bsp   使用   

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

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!