zoukankan      html  css  js  c++  java
  • 注册和登录代码

    注册:

    #1、先把文件内容读出来
    
    user_info = {}
    fw = open('users','a+',encoding='utf-8')
    fw.seek(0)
    for line in fw:
        line = line.strip()
        if line!='':
            username,password,error_count = line.split(',')
            user_info[username] = {'password':password,'error_count':int(error_count)}
    
    for i in range(3):
        username = input('username:').strip().lower()
        password = input('password:').strip()
        cpassword = input('cpassword:').strip()
        if username=='' or password=='' or cpassword=='':
            print('账号?密码、确认密码不能为空')
        elif len(username)<6 or len(username)>12 or  len(password)<6 or len(password)>12:
            print('账号/密码的长度最小6位,最大12位')
        elif password !=cpassword:
            print('两次输入的密码不一致')
        elif username in user_info:
            print('用户名已经存在!')
        else:
            user_str = '%s,%s,0
    '%(username,password)
            fw.write(user_str)
            fw.flush() #
            user_info[username] = {'password': password, 'error_count': 0}
            print('注册成功!')
            # break
    fw.close()

    登录

    # 2、登录 2py
    # 1、账号、密码不能为空
    #2、要校验账号是否存在,不存在要提示
    #3、最多输入3次
    #4、账号不区分大小
    # 5、账号和密码长度要大于等于6,小于等于12
    #6、每次登录的时候密码错误,就这个账号的后面加一个失败次数,
    #7、如果失败次数大于3次的话,提示账号已经被锁定。
    import datetime
    user_info = {}
    fw = open('users','a+',encoding='utf-8')
    fw.seek(0)
    for line in fw:
        line = line.strip()
        if line!='':
            username,password,error_count = line.split(',')
            user_info[username] = {'password':password,'error_count':int(error_count)}
    
    for i in range(3):
        username = input('username:').strip().lower()
        password = input('password:').strip()
        if username=='' or password=='' :
            print('账号?密码不能为空')
        elif len(username)<6 or len(username)>12 or  len(password)<6 or len(password)>12:
            print('账号/密码的长度最小6位,最大12位')
        elif username not in user_info:
            print('用户名不存在!')
        elif user_info[username]['error_count'] >3:
            print('密码输入错误次数太多!')
        elif user_info.get(username).get('password') !=password:
            print('密码错误!')
            user_info[username]['error_count']+=1
        else:
            print('登录成功!%s'%datetime.datetime.now())
            break
    
    
    
    fw.seek(0)
    fw.truncate()
    
    
    
    for username,user_dict in user_info.items():
        password= user_dict.get('password')
        error_count= user_dict.get('error_count')
        user_str = '%s,%s,%s
    '%(username,password,error_count)
        fw.write(user_str)
        fw.flush()
    
    fw.close()
  • 相关阅读:
    梁祝(二胡独奏曲)
    《祝你一路顺风》-吴奇隆
    《祝你一路顺风》-吴奇隆(吉他谱)
    《少年王》片尾曲《白》——吴奇隆(简谱)
    《梁祝》-化蝶(五线谱)
    《西游记》--女儿情(简谱)
    cnn handwrite使用原生的TensorFlow进行预测
    tflearn 中文汉字识别,训练后模型存为pb给TensorFlow使用——模型层次太深,或者太复杂训练时候都不会收敛
    TensorFlow 图像预处理(一) 图像编解码,图像尺寸调整
    迁移学习算法之TrAdaBoost ——本质上是在用不同分布的训练数据,训练出一个分类器
  • 原文地址:https://www.cnblogs.com/Dorami/p/10967273.html
Copyright © 2011-2022 走看看