#!/usr/bin/env python # -*- coding:utf-8 -*- import os,sys num_count = 0 lock_file = 'lockfile.txt' account_file = 'account.txt' match_flag ='' def lock_input(name): f = open(lock_file,'a') f.write(''+name) f.close() while num_count < 3: username = raw_input('请输入用户名 :') password = raw_input('请输入密码 :') f = open(lock_file,'r') for lock_name inf.readlines(): if name ==lock_name.strip(): sys.exit("你的用户名被锁定了,程序将退出") f.close() fd = open(account_file,'r') for line infd.readlines(): user,passwd = line.strip('').split() if user == username and passwd ==password: print '登陆成功' match_flag =True else: print "用户名密码不对" fd.close() if match_flag ==True: break else: print '请重新输入用户名密码!' num_count += 1 else: lock_input(username) ######################################################################################## #!/usr/bin/env python # -*- coding:utf-8 -*- import os,sys num_count = 0 lock_file = 'lockfile.txt' account_file = 'account.txt' match_flag ='' def lock_input(name): f = open(lock_file,'a') f.write(''+name) f.close() def lock_fun(username): f = open(lock_file,'r') for lock_name inf.readlines(): if username ==lock_name.strip(): return 'lock' f.close() def checklogin(username,password): fd = open(account_file,'r') for line infd.readlines(): user,passwd = line.strip('').split() if user == username and passwd ==password: print '登陆成功' return 'ok' else: print "用户名密码不对" fd.close() while num_count < 3: username = raw_input('请输入用户名 :') password = raw_input('请输入密码 :') result =lock_fun(username) if result == 'lock': sys.exit("此账户已经被锁定,程序将退出") match_flag =checklogin(username,password) if match_flag == 'ok': break num_count += 1 else: lock_input(username) ######################################################################################### 使用类 验证时有问题,再找找 #!/usr/bin/env python # -*- coding:utf-8 -*- import sys num_count = 0 lock_file = 'lockfile.txt' account_file = 'account.txt' match_flag ='' class Pername(object): def __init__(self,username,password): self.Username =username self.Password =password def lockcheck(self): f = open(lock_file,'r') for i inf.readlines(): user = i.strip('').split() if self.Username ==user: print user + 'lock文件中的名字' return 'lock' f.close() def login(self): fd = open(account_file,'r') for line infd.readlines(): user,passwd = line.strip('').split() if self.Username == user and self.Password ==passwd: return 'userlogin' fd.close() def lock_input(self): f = open(lock_file,'a') f.write(''+self.Username) f.close() print "账户已经锁定" if __name__ == '__main__': while num_count < 3: username = raw_input('请输入用户名 :') password = raw_input('请输入密码 :') example =Pername(username,password) resultcheck =example.lockcheck() if resultcheck == 'lock': sys.exit('此账户已经被锁定,程序将退出') loginresult =example.login() if loginresult == 'userlogin': print "登陆成功" break num_count += 1 else: example.lock_input()
登陆脚本
免责声明:文章转载自《登陆脚本》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇libffiMac下使用Wine安装PowerDesigner15下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=