zoukankan      html  css  js  c++  java
  • 登陆加密小程序

    自己想的注册登录小程序测试,使用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('	')
            fd.write(hash.hexdigest())
            fd.write('
    ')
        print "注册成功"
    
    def login(user,passwd):
        with open('info.txt') as fd:
            for line in fd:
                if user == line.strip('
    ').split()[0] and passwd == line.strip('
    ').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 
  • 相关阅读:
    JS 操作属性
    JS 操作对象 事件 样式
    JS 一个页面关闭多个页面
    JS DOM
    JS 语言基础
    JS 基础知识
    CSS样式表
    HTML 常用标记
    HTML iframe框架
    28-2 logging 日志模块
  • 原文地址:https://www.cnblogs.com/dachenzi/p/6262536.html
Copyright © 2011-2022 走看看