search
HomeBackend DevelopmentPython TutorialHow to write a login interface?

How to write a login interface?

Jun 20, 2017 pm 01:46 PM
OperationinterfaceLoginwrite

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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you slice a Python list?How do you slice a Python list?May 02, 2025 am 12:14 AM

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

What are some common operations that can be performed on NumPy arrays?What are some common operations that can be performed on NumPy arrays?May 02, 2025 am 12:09 AM

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

How are arrays used in data analysis with Python?How are arrays used in data analysis with Python?May 02, 2025 am 12:09 AM

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

How does the memory footprint of a list compare to the memory footprint of an array in Python?How does the memory footprint of a list compare to the memory footprint of an array in Python?May 02, 2025 am 12:08 AM

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

How do you handle environment-specific configurations when deploying executable Python scripts?How do you handle environment-specific configurations when deploying executable Python scripts?May 02, 2025 am 12:07 AM

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

How do you slice a Python array?How do you slice a Python array?May 01, 2025 am 12:18 AM

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.

Under what circumstances might lists perform better than arrays?Under what circumstances might lists perform better than arrays?May 01, 2025 am 12:06 AM

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

How can you convert a Python array to a Python list?How can you convert a Python array to a Python list?May 01, 2025 am 12:05 AM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools