zoukankan      html  css  js  c++  java
  • 登陆脚本

    #!/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 in f.readlines():         
        if  name == lock_name.strip():             
          sys.exit("你的用户名被锁定了,程序将退出")     
      f.close()
    
      fd = open(account_file,'r')     
      for line in fd.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 in f.readlines():         
        if  username == lock_name.strip():             
          return 'lock'     
      f.close()
    
    def checklogin(username,password):     
      fd = open(account_file,'r')     
      for line in fd.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 in f.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 in fd.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()
     
  • 相关阅读:
    在 Anaconda下解决国内安装tensorflow等下载慢和中断,出错,异常问题的一点思路
    关于指针和结构体的一点教训
    ARM cortexM4中断优先级的一点理解。
    ubuntu16下的/etc/resolv.conf重置的解决方案
    linux安装dpkg安装缺少依赖项的解决
    莲藕的简单凉菜制作总结
    单片机一种简便的printf调试方案。
    usart下位机输出使用printf的格式化技巧
    关于xp操作系统下使用VC6++编写的上位机软件在win10中运行的问题
    百度面试两板斧:手写算法问基础
  • 原文地址:https://www.cnblogs.com/fengjian2016/p/5166839.html
Copyright © 2011-2022 走看看