zoukankan      html  css  js  c++  java
  • 第二阶段---python基础--模拟登陆

    说明:

    1、用户原文件存储在文件中_userinfo

      userinfo文件内容:

      [['li','123'],['z','333']]

    2、判断是否存在登陆错误的用户_被锁定的用户_wrong_name2,没有创建,并写入用户文件头username,带逗号,锁定用户以'逗号'隔开;

    3、判断输入用户是否存在锁定账户中(取出用户名,存入列表,)

    4、逻辑控制,用户名,或秘密超过3次记录该用户的用户名到文件;

    import os
    if os.path.exists('wrong_name2'):
        file_wrong=open('wrong_name2')
        f=file_wrong.readline()
        lock_name=f.split(',')
        for i in lock_name:
            print(i)
        file_wrong.close()
    else:
        with open('wrong_name2','w') as f_wrong:
            f_wrong.write('username')
            f_wrong.write(',')
            lock_name=f_wrong.split(',')
            for i in lock_name:
                print(i)
            file_wrong.close()


    file=open('userinfo2')
    info=eval(file.readline())
    print(info)
    l_name=[]
    l_passwd=[]
    l_count=[]
    count=0
    for i in info:
        l_name.append(i[0])
    for k in info:
        l_passwd.append(i[1])




    while True and count<3:
        name=input('pls input your name:').strip()
        if name in lock_name:
            print('the count is locked...exit.')
            exit()
        while name in l_name and count<3:
            count=0
            while count<3:
                passwd=input('pls input your passwd:').strip()
                if passwd in l_passwd:
                    print('welcome')
                    break
                else:
                    count+=1
                    print('wrong passwd')
                    print(count)
            else:
                l_count.append(name)
                print(l_count)
                f_w=open('wrong_name2','a+')
                f_w.write(str(l_count[-1]))
                f_w.write(',')
                f_w.close()
                print('count>>>%s was locked...'%name)
                exit()
        else:
            count+=1
            print('wrong name...')
            continue
    else:
        l_count.append(name)
        f_w=open('wrong_name2','a+')
        f_w.write(str(l_count[-1]))
        f_w.write(',')
        print('count>>>%s was locked...'%name)

  • 相关阅读:
    spring3.0注解定时任务配置及说明
    程序员,吃什么个对身体好
    log4j 实例 , 浅析
    使用dom4j创建和解析xml
    Java XML解析工具 dom4j介绍及使用实例
    网络原理分析
    Python教程-使用Python解释器
    Jenkins中使用jmeter的脚本
    jmeter: line 129: [: : integer expression expected jmeter: line 200: /usr/bin/java/bin/java: Not a directory解决办法
    阿里云centos安装Jenkins
  • 原文地址:https://www.cnblogs.com/santizhou/p/7409769.html
Copyright © 2011-2022 走看看