码迷,mamicode.com
首页 > 编程语言 > 详细

python 登录验证程序

时间:2016-08-15 22:43:24      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:用户名   password   python   import   输入密码   

Name:  LoginAuth.py

Fuctions: 登录验证、隐藏输入密码、同一用户3次输入错误密码锁定该账户、如果用户名为yooma密码                  为yooma 则登录成功提示欢迎

code:

#!/usr/bin/env python3
#Auther:yooma 2016-08-15 15:00

import sys
import getpass


c = 1

uname = []

while 1:
    username = input("Input username:")
    password = getpass.getpass("Input password:")

    LockFile = open(‘lock.txt‘,‘r‘)
    try:
        if username == LockFile.read():
            print("%s user locked." % username)
            sys.exit(0)
    finally:
        LockFile.close()
    if username == ‘yooma‘ and password == ‘yooma‘:
        print("Welcome %s login success!" % username)
        break
    elif username != ‘yooma‘ or password != ‘yooma‘:
        print("Username or password failed,please input again:")
        uname.insert(c,username)
        s = set(uname)
        for i in s:
           if c < 4 and uname.count(i) == 3:
               LockFile = open(‘lock.txt‘,‘w‘)
               try:
                   LockFile.write(username)
               finally:
                   LockFile.close()
                   print("Your account is locked.")
                   sys.exit(0)
           elif c == 3:
               print("Input error 3 times,go out.")
               sys.exit(0)
        c+=1
        continue
    else:
        print("Input error.")
        break


本文出自 “yooma技术博客” 博客,请务必保留此出处http://yooma.blog.51cto.com/6965726/1838666

python 登录验证程序

标签:用户名   password   python   import   输入密码   

原文地址:http://yooma.blog.51cto.com/6965726/1838666

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!