码迷,mamicode.com
首页 > 编程语言 > 详细

第二阶段---python基础--模拟登陆

时间:2017-08-22 11:00:13      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:rip   username   说明   模拟   存储   passwd   div   while   com   

说明:

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

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)

 

第二阶段---python基础--模拟登陆

标签:rip   username   说明   模拟   存储   passwd   div   while   com   

原文地址:http://www.cnblogs.com/santizhou/p/7409769.html

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