python使用正则表达式检测密码强度源码分享
#encoding=utf-8 #------------------------------------------------------------------------------- #Name: 模块1 #Purpose: # #Author: Administrator # #Created: 10-06-2014 #Copyright: (c)Administrator2014 #Licence: <yourlicence> #------------------------------------------------------------------------------- importre defchecklen(pwd): returnlen(pwd)>=8 defcheckContainUpper(pwd): pattern=re.compile('[A-Z]+') match=pattern.findall(pwd) ifmatch: returnTrue else: returnFalse defcheckContainNum(pwd): pattern=re.compile('[0-9]+') match=pattern.findall(pwd) ifmatch: returnTrue else: returnFalse defcheckContainLower(pwd): pattern=re.compile('[a-z]+') match=pattern.findall(pwd) ifmatch: returnTrue else: returnFalse defcheckSymbol(pwd): pattern=re.compile('([^a-z0-9A-Z])+') match=pattern.findall(pwd) ifmatch: returnTrue else: returnFalse defcheckPassword(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(lenOKandupperOKandlowerOKandnumOKandsymbolOK)
defmain(): ifcheckPassword('Helloworld#123'): print('检测通过') else: print('检测未通过')
if__name__=='__main__': main()