python-学习-正则表达式-强口令检测

题目 强口令检测

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

代码

下面展示代码

#! python3
# StrongPasswordDetection.py # 强口令检测 输入一段口令
# 强口令:长度不少于8个字符 同时包含大写和小写 至少有一位数字
import re
def StrongPasswordDetection(password):
     if len(password) >= 8:
        passRegex_1 = re.compile(r'[a-z]').search(password)
        passRegex_2 = re.compile(r'[A-Z]').search(password)
        passRegex_3 = re.compile(r'\d').search(password)
        if passRegex_1 and passRegex_2 and passRegex_3:
            print('this password is StrongPassword')
        else:
            print('this password is not StrongPassword')
     else:
         print('this password is not StrongPassword')

PassWord = input()
StrongPasswordDetection(PassWord)

结果

12344Saffsg676
this password is StrongPassword

122334456
this password is not StrongPassword
1212233
this password is not StrongPassword
123asD
this password is not StrongPassword
aaaaaaaaFFFF
this password is not StrongPassword
IIIIffg4565
this password is StrongPassword

代码均是本人所写,初识Python,如程序有不规范之处,请多多留言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值