当前位置:网站首页>User login 2
User login 2
2022-06-25 16:09:00 【creedcc】
""" Write user login interface : 1、 Enter the account password to complete the verification , Output after verification " Login successful " 2、 You can log in to different users 3、 The same account is locked three times by mistake ( Tips : The locked user is stored in the file , This ensures that after the program is closed , The user is still locked ) """
""" information Account information in the file : jack:123456:0 word:123:0 hello:123:0 """
import os
flag = True
while flag:
username = input(" Please enter your user name (q or Q sign out ):").strip()
if username.upper() == 'Q':
flag = False
break
# from information Read the user's account in the file 、 Password information
with open('information', encoding='utf-8', mode='r') as f,\
open('infor_copy', encoding='utf-8', mode='w') as ff:
for line in f:
# Note that line breaks are removed , It's cutting
user, pwd, nums = line.strip().split(":")
nums = int(nums)
# First verify whether the entered account exists
if username == user:
# If the user exists , Three chances to enter the password
while nums < 3:
password = input(" Please enter your password :").strip()
if password == pwd:
print(f" Login successful , welcome {
username}")
flag = False
break
else:
nums += 1
print(" I'm sorry , The password you entered is wrong , Please re-enter !")
# Wrong input 3 Time , Prompt that the account has been locked
if nums == 3:
print('sorry, The account has been locked !')
# Write unmodified and modified user data to infor_copy file
ff.write(f'{
user}:{
pwd}:{
nums}\n')
# Delete information file
os.remove('information')
# Rename the modified file to the source file information
os.rename('infor_copy', 'information')
边栏推荐
猜你喜欢

What exactly is a handler

Overall MySQL architecture and statement execution process

Go language - what is critical resource security?

How to reload the win10 app store?

教务系统开发(PHP+MySQL)

The style of the mall can also change a lot. DIY can learn about it!

Principle analysis of ThreadLocal source code

Optimization of lazyagg query rewriting in parsing data warehouse

Uncover gaussdb (for redis): comprehensive comparison of CODIS

Advanced SQL statement 1 of Linux MySQL database
随机推荐
XML usage and parsing of data storage and transmission files
Introduction to database transactions
What plug-ins are available for vscade?
什么是NFT数字藏品?
QC, QA, IPQC, JQE, DQA, SQE, DQC, MQC, IQC, FQC, OQC
地理位置数据存储方案——Redis GEO
Understand the execution sequence of try catch finally in one diagram
10款超牛Vim插件,爱不释手了
What is session? How is it different from cookies?
DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection翻译
js 给元素添加自定义属性
Learning notes of rxjs takeuntil operator
异步处理容易出错的点
The style of the mall can also change a lot. DIY can learn about it!
Load local cifar10 dataset
Analysis of the concept of metacosmic system
ES6 deconstruction assignment rename
Asynchronous processing of error prone points
How to reload the win10 app store?
Uncover gaussdb (for redis): comprehensive comparison of CODIS