python编写登录接口(windows)

Posted on 2018-03-01 11:47  甜心卜乙  阅读(269)  评论(0)    收藏  举报
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#author:han

#编写登录接口,输入用户名和密码,验证成功后进入欢迎界面,输入三次错误后锁定(根据用户名判断)

import os

print os.getcwd()
#创建文件
fp=open('names.txt','a')
fp.close()

#将用户名保存追加到文件
def filename(user):
    type=0
    fp = open('names.txt', 'r')
    lists = fp.readlines()
    if user in lists:
        type = 1
    else:
        fp = open('names.txt', 'a')
        fp.write('\n')
        fp.write(user)
        fp.close()
    fp.close()
    return type

_username='han'
_password='123456'

if __name__=="__main__":
    usr = raw_input('please input username:')
    type = filename(usr)
    if type == 1:
        print  'the user has been locked!'
    else:
        count=0
        while count<3:
            pwd = raw_input('please input password:')
            if usr!= _username or pwd !=_password:
                print 'password is wrong!'
            else:
                print 'welcome to python world!'
                break
            count +=1
            if count ==3:
                print  'the user has been locked!'
                filename(usr)