zoukankan      html  css  js  c++  java
  • Python实践练习:强口令检测

    题目:

    写一个函数,它使用正则表达式,确保传入的口令字符串是强口令。强口令的定义是:长度不少于 8 个字符,同时包含大写和小写字符,至少有一位数字。你可能需要用多个正则表达式来测试该字符串,以保证它的强度。

    分析:

    这题很简单,就是用正则表达式检测是否一个以上数字,有大写和小写字母。

    代码:

    import re
    
    text = str(input('输入一串口令:'))
    
    def checkpw(text):
        flag = True
        if len(text) < 8:
            flag = False
        chpw1 = re.compile(r'[a-z]').search(text)
        chpw2 = re.compile(r'[0-9]+').search(text)
        chpw3 = re.compile(r'[A-Z]').search(text)
        if (chpw1 == None) or (chpw2 == None) or (chpw3 == None):
            flag = False
        if flag:
            print("口令正确")
        else:
            print("口令错误")
    
    checkpw(text)
    

    运行结果:

    输入一串口令:dsaf888DFDHSG
    口令正确
    
    输入一串口令:sdaf33
    口令错误
    
  • 相关阅读:
    网络安全协议(1)
    CG-CTF(6)
    CG-CTF(5)
    CG-CTF(4)
    CG-CTF(3)
    MAC地址欺骗(原理及实验)
    CG-CTF(2)
    CG-CTF(1)
    【转载】Spring Boot【快速入门】2019.05.19
    【编程大系】Java资源汇总
  • 原文地址:https://www.cnblogs.com/wudongwei/p/Python.html
Copyright © 2011-2022 走看看