注册登陆(从文件中获取用户名密码)

注册(regedit.py)

# -*- coding: utf-8 -*-
#__author__:Selid
#__date__:2018/12/21
name=input('请输入用户名').strip()
pwd=input('请输入密码').strip()

with open('account',mode='a') as obj:
    obj.write(name)
    obj.write('*')
    obj.write(pwd+'\n')
    print ('注册成功,欢迎登陆')

with open('account', mode='r') as f:
    for i in f.readlines():
        print(i.split('*'))

登陆(login.py)

# -*- coding: utf-8 -*-
#__author__:Selid
#__date__:2018/12/21

flag=True
count=1
li=[]
while flag:
    name = input('用户名').strip()
    pwd = input('密码').strip()
    mid=[name,pwd]
    with open('account', mode='r',encoding='utf-8') as f:
        for i in f.readlines():
            acc = i.split('*')
            acc[1]=acc[1][:-1]
            li.append(acc)
    if mid in li:
        print('登陆成功')
        flag = False
    else:
        count += 1
        if 3-count >=0:
            print('您输入的用户名或密码错误,请重新输入,您还有{}次机会'.format(4-count))
        else:
            q=input('您还想登陆吗Y/N')
            if q.upper()=='Y':
                count=1
    if count>3:
        flag=False
else:
    print('-------------------')

  

 

转载于:https://www.cnblogs.com/selid/p/10158990.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值