S14 Python3 Day1 Job 2

Source: Internet
Author: User

Demand:

Impersonation verifies that the user enters a password to log in. Requires 3 times, if the user only the wrong password, then three times after the lock, the next time the login will prompt account lockout.

If the user name password is correct, the login is successful.

Do your homework:

Use two text files to store user information and lock information separately

List of users and passwords

[email protected] day1]# cat User_list.txt
Liuxiaolu 123456
Liuxiaogou 888888
Liuxiaomao 654321

Blacklist list

[email protected] day1]# cat User_lock.txt

Program code

#!/usr/bin/env Python3#-*-coding:utf-8-*-#Author:leilei#Defining VariablesTries = 0#Number of attemptsTries_user = 0#Account_flag =0 whileTries < 3: User_list= Open ('/dbdata/pythons/s14/day1/user_list.txt','R') User_lock= Open ('/dbdata/pythons/s14/day1/user_lock.txt','R') user_name= Input ("plz enter ur name:") User_pass= Input ("plz enter ur pass:")         for_user_lockinchuser_lock.readlines (): _user_block=_user_lock.strip (). Split ()ifUser_name = =_user_block[0]:Print("This account has been locked!") Account_flag= 1tries= 4 Break        ifAccount_flag = =0: for_user_nameinchuser_list.readlines (): _user=_user_name.strip (). Split ()ifUser_name = = _user[0] andUser_pass = = _user[1]:                Print("Welcome to login ...,", user_name) tries= 4 Break            elifUser_name = = _user[0] andUser_pass! = _user[1]:                Print("wrong username or password!") Tries_user= Tries_user + 1 Break        Else:            Print("wrong username or password!") Tries= tries + 1ifTries < 4:            Print("u have", 3-tries,"Chances left!\n")        ifTries_user = = 3: User_lock= Open ('/dbdata/pythons/s14/day1/user_lock.txt','a') User_lock.write (user_name+"\ n") User_lock.close ()Print("lots of atempts, ur account has been locked.") User_list.close () user_lock.close ()

Test

[Email protected] day1]#/zuoye2.py--Test account lockout plz enter ur name:liuxiaomaoplz enter ur pass:1wrong username or password!u have2Chances left!plz enter ur name:liuxiaomaoplz enter ur pass:2wrong username or password!u have1Chances left!plz enter ur name:liuxiaomaoplz enter ur pass:3wrong username or password!u have0Chances left!lots of atempts, ur account has been locked. --Prompt to be locked [[email protected] day1]#Catuser_lock.txt liuxiaomao[[email protected] day1]#./zuoye2.py--locked cannot login plz enter ur name:liuxiaomaoplz enter ur pass: OneThis account has been locked![email protected] day1]#./zuoye2.py--test successfully landed plz enter ur name:liuxiaoluplz enter ur pass:123456Welcome toLogin..., liuxiaolu[[email protected] day1]#./zuoye2.py--Test password error plz enter ur name:liuxiaoplz enter ur pass:1wrong username or password!u have2Chances left!plz enter ur name:liuxiaoplz enter ur pass:2wrong username or password!u have1Chances left!plz enter ur name:liuxiaoplz enter ur pass:3wrong username or password!u have0Chances left!

S14 Python3 Day1 Job 2

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.