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 <div class="cnblogs_code"></div><p> 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. <span style="font-family: 宋体; font-size: 16px"></span></p><p> <span style="font-family: 宋体; font-size: 16px"></span></p> <p></p>
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!

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

NumPyallowsforvariousoperationsonarrays:1)Basicarithmeticlikeaddition,subtraction,multiplication,anddivision;2)Advancedoperationssuchasmatrixmultiplication;3)Element-wiseoperationswithoutexplicitloops;4)Arrayindexingandslicingfordatamanipulation;5)Ag

ArraysinPython,particularlythroughNumPyandPandas,areessentialfordataanalysis,offeringspeedandefficiency.1)NumPyarraysenableefficienthandlingoflargedatasetsandcomplexoperationslikemovingaverages.2)PandasextendsNumPy'scapabilitieswithDataFramesforstruc

ListsandNumPyarraysinPythonhavedifferentmemoryfootprints:listsaremoreflexiblebutlessmemory-efficient,whileNumPyarraysareoptimizedfornumericaldata.1)Listsstorereferencestoobjects,withoverheadaround64byteson64-bitsystems.2)NumPyarraysstoredatacontiguou

ToensurePythonscriptsbehavecorrectlyacrossdevelopment,staging,andproduction,usethesestrategies:1)Environmentvariablesforsimplesettings,2)Configurationfilesforcomplexsetups,and3)Dynamicloadingforadaptability.Eachmethodoffersuniquebenefitsandrequiresca

The basic syntax for Python list slicing is list[start:stop:step]. 1.start is the first element index included, 2.stop is the first element index excluded, and 3.step determines the step size between elements. Slices are not only used to extract data, but also to modify and invert lists.

Listsoutperformarraysin:1)dynamicsizingandfrequentinsertions/deletions,2)storingheterogeneousdata,and3)memoryefficiencyforsparsedata,butmayhaveslightperformancecostsincertainoperations.

ToconvertaPythonarraytoalist,usethelist()constructororageneratorexpression.1)Importthearraymoduleandcreateanarray.2)Uselist(arr)or[xforxinarr]toconvertittoalist,consideringperformanceandmemoryefficiencyforlargedatasets.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools
