1. 题目
  2. 代码运行效果
  3. 完整代码
  4. 我的博文推荐
  5. 基础更熟代码更优——再炼同类问题(2022-11-27试炼)


练习题目

密码强度检测 jQuery 密码强度检测器免费_python


回首页




代码运行效果

密码强度检测 jQuery 密码强度检测器免费_密码强度检测 jQuery_02

密码强度检测 jQuery 密码强度检测器免费_字符串_03

密码强度检测 jQuery 密码强度检测器免费_git_04

密码强度检测 jQuery 密码强度检测器免费_python_05


回首页




python完整代码
(如果从语句注释不能清楚作用,请评论区留言指教和探讨。🤝)
#/sur/bin/nve python
# coding: utf-8


#fileName = 'isstrongpassword.py'
def isStrongPassword(s):
    '''密码强度测验'''
    #判断太多,我使用短语句,便于调试查bug
    #判断大小写字母分别不小于1
    lower = len([i for i in s if i.islower()])
    supper = len([i for i in s if i.isupper()])
    if lower>=1 and supper>=1:
        alpha = True
    else:
        alpha = False
    #判断数字不小于3,数字也可以用re提取。我这里是写的函数,觉得用str.isdigit()更好,不用加载re模块。
    if len([i for i in s if i.isdigit()])>=3:
        digit = True
    else:
        digit = False
    #字母和数字的判断,也可以用not in [0~9,[a~z,A~Z]],我选择了用str.is函数,只是我的习惯,二者等价。
    #判断特殊字符不小于3(特殊字符为除字母数字之外的所有字符)
    symbol = len([i for i in s if not (i.islower() or i.isupper() or i.isdigit())])
    if symbol>=3:
        symbol_b = True
    else:
        symbol_b = False
    #判断字符串长度>=12
    if len(s)>=12:
        s_long = True
    else:
        s_long = False
    #下一行为调试打印语句,可以略去
    print(f'\n密码字符判断:\nAlpha={alpha},Digit={digit},Symbol={symbol>=3},密码长度={s_long}')
    if alpha and digit and symbol_b and s_long:
        return True
    else:
        return False


print(f'\n\n{"【密码强度检测器】".rjust(22)}\n\n')
s = input(f'输入密码字符串:\n$>>')
print(f'\n\n密码字符:{s}\n{"﹊"*21}\n{"密码强度:".rjust(16)}{isStrongPassword(s)}\n{"﹊"*21}\n\n')

回首页




题目

密码强度检测 jQuery 密码强度检测器免费_字符串_06

代码
#!/usr/bin/nve python
# coding: utf-8

import re

passwords = input('\n请输入密码:').strip()

# bool
islong = 10 <= len(passwords) <= 15
a, b, c, d = [re.findall(i, passwords) for i in (r'\d', r'_', r'[a-z]', r'[A-Z]')] # re提取数字、下划线、大小写字母。

# is True
if islong and a and b and c and d:
    print(f"\n{' 密码设置成功!':~^43}")
else:
    print(f"\n{' 密码不符合要求,请重新设置!':~^36}")
运行效果截图

密码强度检测 jQuery 密码强度检测器免费_python_07


密码强度检测 jQuery 密码强度检测器免费_python_08


密码强度检测 jQuery 密码强度检测器免费_字符串_09


密码强度检测 jQuery 密码强度检测器免费_git_10