How to write a login interface?
Write login interface
1. Enter username and password
2. Display the welcome message after successful authentication
3. Lock after three incorrect entries
Idea: The requirements are When writing a login interface, there must be a module to store user information; to lock after three times, there must be a module to store locked user information; we know that there are two ways to save user information, one is database saving, and the other is file saving. , now we have only learned about file saving, so there are two files, one is the user information file and the other is the locked user information file.
To read information from a file, add information, and modify information.
readme:
(1) User enters user name;
(2) User Go to the locked file to verify whether the user is locked; if it is locked, ask the user to contact the administrator to solve it;
(3) If it is not locked, go to the user file to verify whether the user exists, and ask the user to enter the password. The welcome message is displayed after successful input; the user is locked after three incorrect inputs;
(4) If the user is not in the user file, it will prompt that the user is not registered and needs to register. Write a registration module to allow the user Register. After registration, add the user to the user list, and display the welcome message, preventing the user from typing, and automatically linking to the login status.
The flow chart is as follows:
active = None #程序执行的标识符 def verification(username):"""验证用户是否锁定"""locked_users = [] with open("locked_file") as locked_f:for line in locked_f: locked_user,locked_pwd = line.split(":") locked_users.append(locked_user) print(locked_users)if username in locked_users: print("对不起,你的用户名已经被锁定,请联系管理员!")else: active = Truereturn active def is_registered(username):"""验证用户是否注册,注册就让用户登录,未注册让用户选择重新输入或者注册"""users = {} with open("active_file","r+") as f:for active_line in f: user,pwd = active_line.split(":") users[user] = pwdif username in users.keys(): test_num = 0while test_num < 3: user_pwd = input("请输入您的密码:")if user_pwd == users[username]: print("welcome back,have a good time!")return Falseelse: test_num += 1else: #用户输入三次以上锁定用户,使用的是while...else...方法 print("对不起,你输入的次数过多,你的用户已经被锁定,请联系管理员!") mes = "\n" + username + ":" + users[username] with open("locked_file","a") as f1: f1.write(mes)return Falseelse: print("您输入的用户名不存在,请按照下面的提示选择!") print("注册:请输入1\n登录:请输入2") num = input("请输入你的选择:")if num == "1": register_name = input("请输入你要注册的用户名:")while True: register_pwd = input("请输入你的密码:") register_pwd2 = input("请再次输入你的密码:")if register_pwd == register_pwd2:breakelse: print("您输入的密码不对,请重新输入") message = "\n" + register_name + ":" + register_pwd print("Thank for your registing,have a good time!") with open("active_file","a") as f_obj: f_obj.write(message)return False elif num == "2": user_name = input("请重新输入你的用户名:") verification(user_name)if __name__ == "__main__": username = input("请输入你的用户名:") active = verification(username)while active: active = is_registered(username)
The above code realizes the verification and locking functions, and also realizes the registration function of new users, but there is a flaw, that is, when When the user is locked, it is not deleted from the current file. It is added to the file that locks the user information. Adding information to the file is very simple, but deleting a piece of information from the file is not very simple. It cannot be operated as you like with a list. You can only convert it first, and when operating files in the list, line breaks and other things are very disgusting. The above code will be converted as follows. Learning is a tedious thing, but it must be done perfectly. Next, I will refer to the code written by others, learn how others delete unnecessary information in the file, and then improve it. the code above.
The above is the detailed content of How to write a login interface?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Some players are experiencing a strange issue on PS4 or PS5 at launch. For example, this can cause distress when their PlayStation Network login fails, but their internet connection is fine. You may encounter errors when entering your login information and may not be able to join PSParty chat. If you encounter a similar problem, this guide may help you solve it. Next to PlayStationNetworkSign-in, you will see the error message ‘AnErrorHaveAreAre’ and it will say ‘Failure’. Other parameters like getting IP address, internet connection and connection speed were successful. So, what could be the problem here? I will give you a job

The AADSTS7000112 error may prevent you from logging into the app using your Microsoft account, causing you inconvenience. This article will provide you with solutions to help you resolve this issue and restore a normal login experience. Login: Sorry, you are having trouble logging in. AADSTS7000112: Application disabled. Fortunately, you can fix the error by following some simple suggestions. What is error code AADSTS7000112? Error code AADSTS7000112 indicates a problem with the connection to Microsoft's Azure Active Directory. Typically, this may be due to the Microsoft application trying to log in being blocked.

When we assemble the computer, although the installation process is simple, we often encounter problems in the wiring. Often, users mistakenly plug the power supply line of the CPU radiator into the SYS_FAN. Although the fan can rotate, it may not work when the computer is turned on. There will be an F1 error "CPUFanError", which also causes the CPU cooler to be unable to adjust the speed intelligently. Let's share the common knowledge about the CPU_FAN, SYS_FAN, CHA_FAN, and CPU_OPT interfaces on the computer motherboard. Popular science on the CPU_FAN, SYS_FAN, CHA_FAN, and CPU_OPT interfaces on the computer motherboard 1. CPU_FANCPU_FAN is a dedicated interface for the CPU radiator and works at 12V

How to log in to the email address of Enterprise WeChat? You can log in to the email address in the Enterprise WeChat APP, but most users don’t know how to log in to the email address. Next is the graphic tutorial on how to log in to the email address of Enterprise WeChat brought by the editor for interested users. Come and take a look! Enterprise WeChat usage tutorial How to log in to the Enterprise WeChat email 1. First open the Enterprise WeChat APP, go to the [Workbench] at the bottom of the main page and click to come to the special area; 2. Then in the workbench area, select the [Enterprise Mailbox] service; 3. Then jump to the corporate email function page, click [Bind] or [Change Email] at the bottom; 4. Finally, enter [QQ Account] and [Password] on the page shown below to log in to the email.

As a modern and efficient programming language, Go language has rich programming paradigms and design patterns that can help developers write high-quality, maintainable code. This article will introduce common programming paradigms and design patterns in the Go language and provide specific code examples. 1. Object-oriented programming In the Go language, you can use structures and methods to implement object-oriented programming. By defining a structure and binding methods to the structure, the object-oriented features of data encapsulation and behavior binding can be achieved. packagemaini
![GeForce Experience login freezes [Fix]](https://img.php.cn/upload/article/000/887/227/171084420790568.png?x-oss-process=image/resize,m_fill,h_207,w_330)
This article will guide you to solve the GeForceExperience login crash issue on Windows 11/10. Typically, this can be caused by unstable network connections, corrupted DNS cache, outdated or corrupted graphics card drivers, etc. Fix GeForceExperience Login Black Screen Before starting, make sure to restart your internet connection and computer. Sometimes, the problem may just be due to a temporary issue. If you are still experiencing NVIDIA GeForce Experience login black screen issue, please consider taking the following suggestions: Check your internet connection Switch to another internet connection Disable your

Wegame is a software used with Tencent games. You can use it to start games and gain acceleration. Recently, many users have experienced prompts that login operations are too frequent when using it. Faced with this prompt, many users do not know How can we solve it successfully? In this software tutorial, we will share the solution with you. Let’s learn about it together. What should I do if Wegame login operations are too frequent? Method 1: 1. First, make sure our network connection is normal. (You can try opening the browser to see if you can access the Internet) 2. If it is a network failure, then try restarting the router, reconnecting the network cable, and restarting the computer to solve the problem. Method 2: 1. If there is no problem with the network, then select &

The steps to install SSH on your Debian11 server and create a new user to allow SSH remote login are as follows: Step 1: Install SSH In order to install the SSH server, you need to log in to your Debian11 server as the root user or a user with sudo privileges. Execute the following command in the terminal to install the SSH server: sudoaptupdatesudoaptinstallopenssh-server Step 2: Create a new user To create a new user, you can use the adduser command. Replace the following command with your desired username: sudoaddusernew_username You will be prompted to set the new user's password and other
