您的位置:首页 > 编程语言 > Python开发

Python 用户登录练习

2016-06-05 22:18 330 查看
#!/usr/bin/env python

#_*_ coding:utf-8 _*_

import os 

import sys

count=3

retry_count=0

account_file='/home/hello/login.txt'

lock_file='/home/hello/lock.txt'

while retry_count < count:

    username=raw_input('input the username: ')

    lock_check=file(lock_file)

    for line in lock_check.readlines():
line=line.split()

        if username == line[0]:
   sys.exit('user is locked')

#            print '%s is locked',username

#            break

    password=raw_input('input the password: ')

    f=file(account_file,'rb')

    match_flag=False

    for line in f.readlines():

        user,passwd=line.strip('\n').split(':')

        if username == user and password == passwd:

            print 'login successful'

            match_flag=True

            break

    f.close()

    if match_flag == True:
print 'enjoy your system'

        break

    elif match_flag == False:

        print 'User is not matched'

        retry_count +=1

#    else:

#        print 'enjoy your system'

else:

    print 'your account is locked'

    f = file(lock_file,'ab')

    f.write(username)

    f.close()

           

note:登录系统,输入用户名和密码,如果三次登录失败的话,将用户进行锁定
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: