zoukankan      html  css  js  c++  java
  • python3 验证用户名密码

     输入用户名,密码,匹配通过,不匹配报错

    import getpass
    
    user = input('input username: ')
    pwd = getpass.getpass('input password: ')
    
    if user == 'xp' and pwd == 'xp0001':
        print("welcome %s" % user)
    else:
        print("Error username or password")
    

      

    增加计数,大于3次报错

    import getpass
    user_info = {}
    
    a = {'xp':{'pwd':'xp0001','block':0}}
    
    count = a.get('xp')['block']
    print(count)
    while count < 3:
        user = input('input username: ')
        pwd = getpass.getpass('input password: ')
    
        if user == 'xp' and pwd == 'xp0001':
            print("welcome %s" % user)
            break
        else:
            print("Error username or password,retry")
    
        count += 1
    else:
        print("%s is locked" % user)
        a['xp']['block'] = 3
    

      

    可是这样再执行的时候,block值还是返回0,增加个文件吧

  • 相关阅读:
    MD5算法MFC实现
    asp.net2.0新特点
    file format
    C专家编程第二章学习笔记
    Bye Czech golden generation
    中间层
    学完谭C之后
    C语言学习之路
    荀子劝学篇
    C语言常用转义字符表
  • 原文地址:https://www.cnblogs.com/xp1005/p/6223338.html
Copyright © 2011-2022 走看看