学习笔记《Python编程快速上手-让繁琐工作自动化》第七章

7.18.1 强口令检测

import re


def pwdcheck(pwd):
	strpc = "你的密码"
	pwdn = 5
	numbercheck = re.compile(r'\d').search(pwd)
	uppercheck = re.compile(r'[A-Z]').search(pwd)
	lowercheck = re.compile(r'[a-z]').search(pwd)
	othercheck = re.compile(r'[!@#$%^&\*()_+~\=\-\[\]\\\{\}\|\;\'\:\"\,\.\/\<\>\?]').search(pwd)
	if len(pwd) >= 8:
		pwdn -= 1
	else:
		strpc += "小于8位,"
	if numbercheck != None:
		pwdn -= 1
	else:
		strpc += "未包含数字,"
	if uppercheck != None:
		pwdn -= 1
	else:
		strpc += "未包含大写字母,"
	if lowercheck != None:
		pwdn -= 1
	else:
		strpc += "未包含小写字母,"
	if othercheck != None:
		pwdn -= 1
	else:
		strpc += "未包含特殊字符,"
	if pwdn == 0:
		print(strpc + "符合所有安全强度要求,如果可以使用中文,请使用中文")
	else:
		print(strpc + "将重新检测密码强度.")
		setpwd()


def setpwd():
	pwd =input("请输入8位以上密码其中包含大小写字母,数字及特殊字符:\n")
	pwdcheck(pwd)



7.18.2 strip()的正则表达式版本

import re
def re_strip(msg,msgrp=None):
    if msgrp is None:       
        regex = re.compile(r'^[\s]*|[\s]*$')
    else:       
        regex = msgrp
    return re.sub(regex,"",msg)

a=" \t \n  112321233123 \t \n"

re_strip(a)
re_strip(a,"123")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值