Home Backend Development Python Tutorial Detailed introduction to the login module in python

Detailed introduction to the login module in python

Jul 21, 2017 pm 02:19 PM
Operation practise

Login module:

No matter which website we go to, we often encounter this situation. Let us log in to this website. The flow chart is as follows:

Ideas:

1. When we log in to the website, we first enter the user name , at this time, some websites will remind us whether the user name exists. If the user name we enter does not exist, a prompt will appear telling us that the user name does not exist. At this time, we need to re-enter it or choose to register. Of course, We just ask the user to re-enter here;

2. If the username exists, you need to enter the password. We know that when entering the password, we do not verify whether the password is correct. If Directly verifying whether the password is correct first will lose the role of letting the user enter the verification code. Therefore, we always do not verify the password first, but let the user enter the verification code, and first verify whether the verification code entered by the user is correct;

 3. If the verification code is incorrect, ask the user to re-enter the verification code; if the verification code is correct, then it is time to return to re-verify whether the password is correct; if the password is correct, the login is successful. ; Otherwise, if the password is incorrect, the user needs to re-enter the password at this time. Since the user has already entered the user name at this time, there is no need to re-enter the user name, only the password and verification code are required; that is, Re-enter the password, and then enter the verification code; if the password is correct, the login is successful, otherwise re-enter the password and verification code. The verification code must be entered every time you enter the password;

To achieve The function of the above code must use a while loop. Since it is checked layer by layer, the input of the user name must be a loop until the user enters the correct verification code. The key is how to ensure that the user name is correct when the password or verification code is used. When you make a mistake, you don’t need to re-enter the username, otherwise it will be looked down upon. At this time, you need to consider that when the username is correct, you need to stop the cycle and the next time the user enters the password or verification code, it cannot be executed. When cyclically entering user names.

The code is implemented as follows:

 

def login(name,password):'''用户登录模块,用户登录时候的各种设置,本次实现功能''''''用户登录验证的时候,一般会先判断验证码是否正确,因此要让用户首先验证验证码'''active = Truewhile True:while active:
            username = input("请输入你的用户名:")'''首先验证用户名是否存在'''users = []for user_list in userfile.usernames:
                users.append(user_list[0])if username in users:
                active = Falseelse:
                print("对不起,您输入的用户名不存在,请重新输入:")
        pwd = input("请输入你的密码:")while True:'''加入一个用户输入验证码的模块,让用户输入验证码'''verification_code = str(random.randint(0,9)) + chr(random.randint(65,90)) + str(random.randint(0,9)) + chr(random.randint(97,122))
            print(verification_code)
            test_num = input("请输入验证码:")if test_num == verification_code.lower() or test_num == verification_code.upper():'''无论用户输入大小写都可以验证成功''''''用户验证成功后,开始进行用户自己的认证,是否注册,或者用户名正确'''breakelse:
                print("您输入的验证码有误,请重新输入!")if [username,int(pwd)] in userfile.usernames:
            print("Successful!")return (username,pwd)else:
            print("对不起,您输入的密码有误,请重新输入:")
Copy after login

The above code Run as follows:

请输入你的用户名:geng
请输入你的密码:1233D0t
请输入验证码:3d0t
对不起,您输入的密码有误,请重新输入:
请输入你的密码:2228I9z
请输入验证码:8888您输入的验证码有误,请重新输入!
2G0j
请输入验证码:8888您输入的验证码有误,请重新输入!
7T1a
请输入验证码:7t1a
对不起,您输入的密码有误,请重新输入:
请输入你的密码:22227X4q
请输入验证码:7x4q
对不起,您输入的密码有误,请重新输入:
请输入你的密码:6662O0q
请输入验证码:2o0q
Successful!('geng', '666')
Copy after login

The execution result of the above code is as shown above. When we want to stop a loop alone, we can set an identifier for this loop to open or close the loop. When the conditions are met, close this loop. Loop, so that this loop will not be opened when executing other programs;

active = True
while True:
while active ; #'' '
Users = [] for User_list in Userfile.usernames:
Users.appnd (User_list [ 0]) # #if username in users:
                      active = False
               else:                     
print("
Sorry, the username you entered does not exist , please re-enter: ") ​​ pwd =
input("
Please enter your password: ")

With the above code, we have achieved such a function. When we want to stop this cycle, we Let the identifier of the inner loop be closed.

The above is the detailed content of Detailed introduction to the login module in python. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to practice typing with Kingsoft Typing Guide - How to practice typing with Kingsoft Typing Guide How to practice typing with Kingsoft Typing Guide - How to practice typing with Kingsoft Typing Guide Mar 18, 2024 pm 04:25 PM

Nowadays, many friends like to use Kingsoft Typing Assistant, but the typing speed seriously affects work efficiency, so I teach you to practice typing speed. So how to use Kingsoft Typing Assistant to practice typing? Today, the editor will give you a tutorial on how to practice typing numbers with Kingsoft Typing Assistant. The following is described, I hope it will be helpful to everyone. First, open the Kingsoft typing software, then click the (Getting Started) button with your mouse, then click the (Number Keys) button in a new window, then click the (Start from Scratch) button below to practice, or click the (Test Mode) button. , just enter numbers for practice. In addition, Kingsoft Typing Assistant has other functions that can help you practice typing better. 1. Select practice mode: On the software interface, you can see that there are different practice modes, such as "New

How to practice Wubi typing for beginners - Wubi input method typing practice How to practice Wubi typing for beginners - Wubi input method typing practice Mar 18, 2024 pm 06:30 PM

Wubi typing, also known as Wubi input method, is an efficient Chinese character input method. For beginners, mastering Wubi typing requires a certain amount of time and patience. Below, the editor has compiled the learning methods for Wubi typing beginners. Let’s take a look! 1. Understand the principles of Wubi font Wubi font is a type of font based on Input method for strokes and radicals. Each Chinese character can be composed of different strokes and radicals. Therefore, the key to learning Wubi font is to understand the combination rules of strokes and root characters. In the five-stroke font, there are five basic strokes: horizontal, vertical, left, right, and fold. These basic strokes can be combined into different radicals, which in turn can be combined into complete Chinese characters. 2. Learn the radicals and key positions. In Wubi font, each letter key corresponds to one or more radicals. therefore

How can I resubmit my Xuexitong homework if it was rejected? -How do I check the number of times I have studied a Xuexuetong chapter? How can I resubmit my Xuexitong homework if it was rejected? -How do I check the number of times I have studied a Xuexuetong chapter? Mar 18, 2024 pm 08:49 PM

How can I resubmit my Xuexitong homework if it was rejected? 1. Find the notice that the assignment has been knocked back. 2. Find the information about the returned job. 3. Click on the blue assignment to re-modify and submit the assignment. How do I check the number of times I have studied a Xuexuetong chapter? First, enter Xuedutong and click "Me" in the lower right corner. Next, next to the individual's name, there is a small logo, click on it. Finally, when the sign is clicked, the number of times Xuetong has been used will be available.

How can I resubmit my Xuexitong homework if it was rejected? -How to watch videos on Xuexuetong? How can I resubmit my Xuexitong homework if it was rejected? -How to watch videos on Xuexuetong? Mar 18, 2024 pm 05:55 PM

XueTong is a domestic knowledge dissemination and management sharing platform based on the principles of nervous system. It makes use of the massive books, journals, newspapers, videos, originals and other resources accumulated by Chaoxing over the past 20 years, and integrates knowledge management, course learning, and special topic creation to provide readers with a one-stop learning and working environment. Many students will encounter this problem when studying online courses: If they make a mistake in their homework, how do they submit it if they have to redo it? Today, let the editor explain to you how to re-submit your Xuexuetong homework after it was rejected, and how to watch the videos on Xuexuetong! 1. How to resubmit a Xuexitong assignment that has been rejected. Step 1: After opening the Xuexitong software, click "Course" on the homepage. Step 2: In the course list, you can find the returned course assignment, "Rejected Course" Click

Regular expression exercises in Java Regular expression exercises in Java Jun 16, 2023 pm 02:36 PM

In Java, regular expressions are one of the most commonly used technologies and can be used in almost any text processing scenario, such as text search, extraction, analysis, replacement, etc. Its powerful matching capabilities can greatly improve development efficiency, while making the code more concise and easier to maintain. The following are some regular expression exercises in Java to help you master the application of regular expressions. Regular expression for matching Chinese characters: [u4e00-u9fa5] Explanation: The Unicode code value range of Chinese characters is from 4e00 to 9f

How to open the quick job floating window? How to quickly open a floating window for a job How to open the quick job floating window? How to quickly open a floating window for a job Mar 16, 2024 pm 01:52 PM

Kuaizuozuo is a homework tutoring software specially created for students and teachers. It can quickly help everyone find the correct answer and has corresponding analysis, which has brought great help to students' learning. So do you know how to open the floating window of the quick assignment? Let us find out together. How to open the quick job floating window? Open the settings on the home screen of your phone. Scroll down and click [Privacy]. Click *, [Permission Management]. Scroll down and click [Floating Window]. Find Quick Pair in the list of apps or use search to find it and click the right button to turn on permissions. Function introduction 1. Search analysis Scan the barcode to get full text analysis, keyword search, and category search in seconds

I can't pass the basic PHP written test, how can I improve? I can't pass the basic PHP written test, how can I improve? Mar 01, 2024 pm 12:12 PM

PHP is a language widely used in the field of web development, and mastering its basic knowledge is crucial for those engaged in PHP development. When facing a situation where you fail to pass the basic PHP written test, it is crucial to improve your PHP capabilities. The following will introduce how to improve the basic knowledge of PHP from several aspects. First of all, it is recommended to systematically learn the PHP language from the basics, including basic knowledge such as syntax, variables, constants, operators, arrays, functions, etc. You can learn P systematically by reading relevant books, watching online tutorials or attending training courses

How to implement a simple student homework submission deadline reminder system in Java? How to implement a simple student homework submission deadline reminder system in Java? Nov 02, 2023 pm 02:08 PM

How to implement a simple student homework submission deadline reminder system in Java? With the development and popularization of education, students need to submit various assignments to teachers. In order to better manage student homework and remind students to submit homework on time, we can use the Java programming language to implement a simple student homework submission deadline reminder system. First, we need to design a student class and assignment class. publicclassStudent{privateStringname

See all articles