Getting started with Python 14-day Camp • 1th python basic syntax-Write login Authentication Program

Source: Internet
Author: User

Job Title: Write the login authentication procedure

  • Job Requirements:

    Basic requirements: Let the user enter the user name password Authentication successful display welcome information after the error three to exit the program upgrade requirements: can support multiple users login (prompt, through the list to save multiple account information) Users 3 times authentication failed, quit the program, restart the program when you try to log on, or lock the status (prompt: Need to save user-locked state to file)
    1 #!/usr/bin/env python2 #-*-coding=utf-8-*-3 """4 @author: Wllen5 @file: user_pass.py6 @time: 2018/5/14 11:447 """8user = {9     "Wllen": {"Password": 123456},Ten     "Alex": {"Password":"abc123"}, One     "Peiqi": {"Password":"qwe456"} A } -Count =0 -f = Open (file="Lock.txt", mode="R", encoding="Utf-8")#Open lock.txt File theLock_user =F.read () -Exit_flag = False#exit Flag bit -Username = input ("Please enter your user name:"). Strip () -  while  notExit_flag: +     ifUsernameinchLock_user:#determine if the user name is locked -         Print("Sorry, the user has been locked out, please contact the administrator to handle! ") +     Else: A         ifUsername not inchUser#determine if the user name exists at             Print("user name does not exist, please re-enter! ") -         Else: -             ifCount < 3:#Cycle 3 times -Password = input ("Please enter your password:"). Strip () -                 ifPassword = = user[username]["Password"]:#Verify user name password -                     Print("welcome%s to the world of Python!"%username) in                      Break -                 Else: to                     Print("Sorry, the password you entered is wrong, please re-enter!") +Count + = 1 -                     Continue the             Else: *With open ('Lock.txt','A +') as F:#write a locked user name to a file $ f.write (username)Panax NotoginsengF.write ('\ n') -                     Print("Sorry, your account%s has been locked! "%username) theExit_flag = True
    View Code

Getting started with Python 14-day Camp • 1th python basic syntax-Write login Authentication Program

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.