Home  >  Article  >  Backend Development  >  Writing login interface in python

Writing login interface in python

高洛峰
高洛峰Original
2017-02-17 11:44:161244browse
#coding:gbk
#author:zhb

import getpass,os,sys

os.system('cls')

i=0
while i<3:
    name=raw_input('输入用户名:')

    lock_file=open(r'account_lock.txt','r+')
    for lock_line in lock_file.readlines():
        lock_line=lock_line.strip('\n')
        if lock_line==name:
            sys.exit('用户 %s 存在于被锁定文件中!请重新登录运维平台!再见!' %name)
        else:
            pass

 user_file=open(r'account.txt','r')
    for user_line in user_file.readlines():
        (user,password)=user_line.strip('\n').split()
        if user==name:
            j=0
 while j<3:
                passwd=getpass.getpass("input password:")
                if password==passwd:
                    sys.exit("热烈欢迎 %s 进入运维平台" %name)
                else:
                    if j!=2:
                        print("密码输入错误, 用户 %s 还有 %d 次输入机会"  %(name,2-j))
                j+=1
 else:#密码输错3次,锁定并追加到account_lock.txt里
 lock_file.write(name+'\n')
                sys.exit("由于连续输入密码3次错误, 该账号 %s 已被锁定,请联系IT人员进行解绑" %name)
    else:
        pass
 i+=1
else:
    sys.exit('系统中不存在用户 %s ,请重新登录'  %name)

For more articles related to writing login interfaces in python, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:python basics--listNext article:python basics--list