Python basic practice-User Login implementation code sharing, python User Login

Source: Internet
Author: User

Python basic practice-User Login implementation code sharing, python User Login

Python version: python3.5

1. Requirements

1) enter the user name and password
2) The welcome information is displayed after the authentication is successful.
3) Lock after three wrong attempts

2. Demand Analysis

1) User information is stored in the file (login/config/user_login.txt)
2) enter the user name and password
3) Determine whether the user name exists. If the user name exists, continue. If the user name does not exist, continue to enter the user name.
4) Determine whether the user name has been locked. If the user name has been locked, exit the program. Otherwise, continue.
5) match the user information in the file
6) If yes, the welcome information is printed.
7) if three wrong passwords are entered, the user name (login/config/name_lock.txt) will be locked)

3. Test the user

Bigberg: 123abc
Lc: 123456
Smallberg: 111111
Root: 12345
Dinasor: 12321

#-*-Coding: UTF-8-*-# Author: bigberg # define a cyclic count = 0 # define a dictionary storage username and password names ={}# define a list storage username name_exit = [] # enter username = input ("username ": ") # determine whether the user entered is in the user name list with open (".. /config/name_login.txt ", 'R') as f: while True: line = f. readline (). strip () if not line: break else: name = line. split (':') [0] passwd = line. split (':') [1] names [name] = passwdfor key in names: name_exit.append (key) # determine whether the user name is correct. If it is incorrect, follow Enter while username not in name_exit: print ("The account is not exit. check it again. ") username = input (" username: ") else: # Read the content in the locked file with open (".. /config/name_lock.txt "," r ") as f: lock_name = f. read () # determine whether the user name is in the locked file. if the user name is in the locked file, exit the program if username = lock_name: print ("Sorry. your account has been locked. ") exit () else: #3 chance to enter the password while count <3: passwd_input = input (" password: ") # determine whether the user name and password are valid if passwd_ I Nput = names [username]: print ("Welcome! ", Username) break else: print (" Error, please try again. ") count + = 1 # if three wrong passwords are entered, add the user name to the locked file if count = 3: with open (".. /config/name_lock.txt "," w ") as f: f. write ("% s" % username) print ("You have tried 3 times, and your account will be locked ")

Summary

The above is all about the user logon implementation code of the basic Python exercises in this article. I hope it will be helpful to you. If you are interested, you can continue to refer to this site: Python getting started with trigonometric function full solution [favorites], python fun project-sharing of pornographic image recognition code, Python Implementation of a simple verification code program, etc, if you have any questions, you can leave a message at any time. The editor will reply to you in a timely manner. Thank you for your support!

Related Article

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.