面试题:写一个密码验证的方法,来验证密码策略

#-*-coding:utf-8-*-
#__author__='maxh'
#验证密码策略
# 1.长度在6到12位
# 2.首字母大写
# 3.必须包含大小写字母数字特殊字符

charsLower="abcdefghigklmnopqrstuwdxyz"
charsUpper=charsLower.upper()
nums="0123456789"
specials="~!@#$%^&*"

def checkPsw(psw):
    status = [False, False, False, False]
    if len(psw)>12 or len(psw)<6:
        print("密码位数不正确,请保持在6-12位")
    elif psw[0] not in charsUpper:
        print("密码首字母需要是大写字母")
    else:
        for c in psw:
            if c in charsLower:
                status[0]=True
            elif c in charsUpper:
                status[1]=True
            elif c in nums:
                status[2]=True
            elif c in specials:
                status[3]=True
            else:
                print("出现了一个不再控制范围内的字符%s"%c)
    if False in status:
        return False
    else:
        print("密码符合规则")
        return True

if __name__ == "__main__":
    checkPsw("123456")
    checkPsw("12356")
    checkPsw("A45ab@d")
    checkPsw("A45ab(d")

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值