python使用正则表达式检测密码强度源码分享

yipeiwu_com6年前Python基础

复制代码 代码如下:

#encoding=utf-8
#-------------------------------------------------------------------------------
# Name:        模块1
# Purpose:
#
# Author:      Administrator
#
# Created:     10-06-2014
# Copyright:   (c) Administrator 2014
# Licence:     <your licence>
#-------------------------------------------------------------------------------
import re
def checklen(pwd):
    return len(pwd)>=8
def checkContainUpper(pwd):
    pattern = re.compile('[A-Z]+')
    match = pattern.findall(pwd)
    if match:
        return True
    else:
        return False
def checkContainNum(pwd):
    pattern = re.compile('[0-9]+')
    match = pattern.findall(pwd)
    if match:
        return True
    else:
        return False
def checkContainLower(pwd):
    pattern = re.compile('[a-z]+')
    match = pattern.findall(pwd)
    if match:
        return True
    else:
       return False
def checkSymbol(pwd):
    pattern = re.compile('([^a-z0-9A-Z])+')
    match = pattern.findall(pwd)
    if match:
        return True
    else:
        return False
def checkPassword(pwd):
    #判断密码长度是否合法
    lenOK=checklen(pwd)
    #判断是否包含大写字母
    upperOK=checkContainUpper(pwd)
    #判断是否包含小写字母
    lowerOK=checkContainLower(pwd)
    #判断是否包含数字
    numOK=checkContainNum(pwd)
    #判断是否包含符号
    symbolOK=checkSymbol(pwd)
    print(lenOK)
    print(upperOK)
    print(lowerOK)
    print(numOK)
    print(symbolOK)
    return (lenOK and upperOK and lowerOK and numOK and symbolOK)

def main():
    if checkPassword('Helloworld#123'):
        print('检测通过')
    else:
        print('检测未通过')

if __name__ == '__main__':
    main()

平时用正则不多,不知道怎么写一个正则满足要求,用了比较笨的办法,谁知道一句正则检验的请赐教!

相关文章

pandas的qcut()方法详解

pandas的qcut()方法详解

pandas的qcut可以把一组数字按大小区间进行分区,比如 data = pd.Series([0,8,1,5,3,7,2,6,10,4,9]) 比如我要把这组数据分成两部分,一...

Windows系统配置python脚本开机启动的3种方法分享

Windows系统配置python脚本开机启动的3种方法分享

测试环境:windows Server 2003 R2 一、开始菜单启动项实现 用户必须登录才可执行。 测试脚本(python代码): 复制代码 代码如下: import time fo...

python 中random模块的常用方法总结

python 中random的常用方法总结 一、random常用模块 1.random.random() 随机生成一个小数 print(random.random()) # 输出...

Python编程中装饰器的使用示例解析

装饰函数和方法 我们先定义两个简单的数学函数,一个用来计算平方和,一个用来计算平方差: # get square sum def square_sum(a, b): return...

ActiveMQ:使用Python访问ActiveMQ的方法

ActiveMQ:使用Python访问ActiveMQ的方法

Windows 10家庭中文版,Python 3.6.4,stomp.py 4.1.21 ActiveMQ支持Python访问,提供了基于STOMP协议(端口为61613)的库。 Act...