第一个小程序

本文介绍了一个简单的用户登录验证系统实现方法。通过读取文件中预存的用户名和密码,进行登录验证,并对错误输入的次数进行了限制。同时,对于连续输入错误的用户账号将被锁定。

 

 
# edit by weiwei xu
# -*- coding:UTF-8 -*-
f=open('user','r',encoding='utf-8')
fstr=f.readlines()#读文件,读出来是列表
fuser=fstr[0:-1:2]#从开始没隔一个取一个值,这个是account
fpword=fstr[1::2]#这个是password,中间不写0.才能取到最后一个值
i = 1
while i <= 3:
account=str(input("please input your account:"))
password=str(input("please input your password:"))
for n in fuser:
fuser_account=n.strip()#取account付给变量,方便进行字符串对比
if account == fuser_account:
for m in fpword:
fuser_pword=m.strip()#取密码值付给变量以便后面进行对比
if password==fuser_pword:
print("welcome to my school")
exit()
f = open('incorrect-user', 'r', encoding='utf-8')#读取incorrect-user账户里账号,准备做对比
for line in f:
fuser_lock=(line.strip())
if account==fuser_lock:#判断account是否已被锁定
print("your account has been locked")
exit()
i=i+1
print("your account is incorrect ,please re-enter:")
f=open('incorrect-user','a+',encoding='utf-8')
f.write(account+"\n")
print("your account has been locked")

转载于:https://www.cnblogs.com/xuxiaole/p/8647410.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值