码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-12-21 22:49:35      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:gedit   print   regedit   文件   python   input   str   lag   login   

注册(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=open(‘account‘,mode=‘a‘)
    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(‘-------------------‘)

  

 

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

标签:gedit   print   regedit   文件   python   input   str   lag   login   

原文地址:https://www.cnblogs.com/selid/p/10158990.html

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