Python User password login match verification

Source: Internet
Author: User

#需求

Writing the Login interface

-Enter user name password

-Show welcome message after successful authentication

-three times after the wrong lock



#脚本目录

[Email protected] opt]# tree ├──account_lock.txt├──accounts.txt└──login.py0 directories, 3 files


#脚本文件

#!/usr/bin/env python#_*_ coding:utf-8 _*_import sysretry_limit = 3retry_count  = 0account_file =  ' accounts.txt ' lock_file =  ' account_lock.txt ' While retry_ count < retry_limit:   #三次验证循环          #让用户输入用户名         username = raw_input (' \033[31m Username: \ 033[0m ')         lock_check = file (lock_file)          for line in lock_check.readlines ():                 if username in line:                          sys.exit ()                                  # Let the user enter the password            password = raw_input (' \033[ 31m password: \033[0m ')                   #获得account文件的用户和密码         f = file ( Account_file, ' RB ')         match_flag = False         for line in f.readlines ():                 user,passwd = line.strip (' \ n '). Split ()                                   #对用户输入的用户密码进行匹配验证      &nbSp;          if username == user and  password == passwd:                         print  ' match! ',  username                          match_flag = True                         break         f.close ()                   #判断有没有匹配成功, the next cycle is unsuccessful, the welcome information is entered          if match_flag == False:                    print  ' user unmatched '                  retry_count += 1         else:                 print  "welcome login wsyht lerning system!"                 sys.exit () Else :         #三次循环完后开始锁账户          print  ' your account is locked! '         f = file (lock_file, ' ab ')          f.write (username)         f.close ()


#查看账户文件

[email protected] opt]# cat accounts.txt wsyht wsyht


#查看锁文件

[email protected] opt]# cat account_lock.txt [[email protected] opt]#


#执行脚本不匹配显示

[[email protected] opt]# python login.py username:jenkins password:jenkinsuser unmatched username:jenkins password:je Nkinsuser unmatched Username:jenkins password:jenkinsuser unmatchedyour account is locked!


#查看锁文件

[email protected] opt]# cat account_lock.txt jenkins[[email protected] opt]#


#执行脚本匹配显示

[email protected] opt]# python login.py username:wsyht password:wsyhtmatch! Wsyhtwelcome Login Wsyht lerning System


This article is from the "Wsyht blog" blog, make sure to keep this source http://wsyht2015.blog.51cto.com/9014030/1794940

Python User password login match verification

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.