Python Basic Practice (i) Impersonate user login

Source: Internet
Author: User

Development environment: Windows

Editor: Pycharm

Python Environment: 3.6

Basic requirements: Write a login

    • Enter User name password

    • Show welcome message after successful authentication

    • Three-time error after locking

Basic ideas:

1. Define user and password

2. Define the number of logins

3, using while loop to achieve the number of judgments

4. While loop nesting if else loop to implement the user name and password verification, if successful, display the login success, if the failure continues to log in, while the count part plus 1;

code example:

#!/usr/bin/env python#_*_coding:utf-8_*_#author pengimport getpassusername=  "Admin" password= "admin" count=0print ('----*****web Management System * * * * *-----') while count<3:    login_ Username=input ("Input your username:")     login_password=input ("Input your  password: ")     if login_username ==username and login_password== Password:        print ("Welcome to login:  %s"  %login_username)          break    elif login_username != username or login_password!=password:        print  ("% s time landing failed, please re-login! " %count)     count +=1    if count==3:         print  ("You have entered the error 3 times to temporarily lock your users")          breakprint ('----*****web Management System Exit * * * *-----') 

Test results:

C:\Users\Administrator\AppData\Local\Programs\Python\Python35\python.exe c:/users/administrator/pycharmprojects /s14/pc.py----*****web Management System * * * * * * *-----Input your username:useinput your password:www the No. 0 time landing failed, please re-login! Input your username:wwwinput your password:222 1th time login failed, please re-login! Input your username:wwwinput your password:eee 2nd time login failed, please re-login! You have entered the error 3 times to temporarily lock your user----*****web management system EXITS * * * *-----entered correctly: C:\Users\Administrator\AppData\Local\Programs\Python\ Python35\python.exe c:/users/administrator/pycharmprojects/s14/pc.py----*****web Management System * * * * * * *-----input your username: Admininput your password:admin welcome you to login: admin----*****web Management System QUIT * * * *-----

Summary and optimization here only need to determine the password and user name is correct, incorrect certainly can not login so only with else on the same time that the login count print is the count value, the initial value is starting from 0, the count should be starting from 1, the part is not annotated, and needs to be optimized later.

Python Basic Practice (i) Impersonate user login

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.