zoukankan      html  css  js  c++  java
  • 两种方法思考密码安全性

    方法一:
    #前置条件
    symbol='~!@#$%^&*()_=-/,.?<>;:[]{}|'
    letter='abcdefghijklmnopqrstuvwxyz'
    nums='0123456789'
    #判断密码安全性的程序
    print('您好,请输入密码:')
    passwd=input()
    #首先判断一下用户输入的是不是空值
    lenth=len(passwd)
    while (lenth==0) or (passwd.isspace()):
        print('密码不能为空,请重新输入:')
        passwd=input()
        lenth=len(passwd)
    #判断长度
    if lenth<=8:
        lenrs=1
    elif 8<lenth<=16:
        lenrs=2
    else:
        lenrs=3
    #判断是否有特殊符号
    syrs=0
    for each in symbol:
        if each in passwd:
            syrs+=1
    #判断是否有字母
    lers=0
    for each in letter:
        if each in passwd:
            lers+=1
    #判断是否有数字
    numrs=0
    for each in nums:
        if each in passwd:
            numrs=1
    #整个的判断
    if lenrs==1 or numrs==lenth or lers==lenth:
        print('您的密码安全系数较低')
    elif lenrs==3 and syrs!=0 and lers!=0 and numrs!=0 and passwd[0] in letter:
        print('您的安全系数为高,请继续保持')
    else:
        print('您的安全系数为中')
     
    方法二:
    # 密码安全性检查代码
    #
    # 低级密码要求:
    #   1. 密码由单纯的数字或字母组成
    #   2. 密码长度小于等于8位
    #
    # 中级密码要求:
    #   1. 密码必须由数字、字母或特殊字符(仅限:~!@#$%^&*()_=-/,.?<>;:[]{}|)任意两种组合
    #   2. 密码长度不能低于8位
    #
    # 高级密码要求:
    #   1. 密码必须由数字、字母及特殊字符(仅限:~!@#$%^&*()_=-/,.?<>;:[]{}|)三种组合
    #   2. 密码只能由字母开头
    #   3. 密码长度不能低于16位
     
    symbols = r'''`!@#$%^&*()_+-=/*{}[]|'";:/?,.<>'''
    chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    nums = '0123456789'
     
    passwd = input('请输入需要检查的密码组合:')
     
    # 判断长度
    length = len(passwd)
     
    while (passwd.isspace() or length == 0) :
        passwd = input("您输入的密码为空(或空格),请重新输入:")
        length = len(passwd)
     
    if length <= 8:
        flag_len = 1
    elif 8 < length < 16:
        flag_len = 2
    else:
        flag_len = 3
     
    flag_con = 0
     
    # 判断是否包含特殊字符
    for each in passwd:
        if each in symbols:
            flag_con += 1
            break
        
    # 判断是否包含字母
    for each in passwd:
        if each in chars:
            flag_con += 1
            break
     
    # 判断是否包含数字
    for each in passwd:
        if each in nums:
            flag_con += 1
            break    
     
    # 打印结果
    while 1 :
        print("您的密码安全级别评定为:", end='')
        if flag_len == 1 or flag_con == 1 :
            print("低")
        elif flag_len == 2 or flag_con == 2 :
            print("中")
        else :
            print("高")
            print("请继续保持")
            break
     
        print("请按以下方式提升您的密码安全级别:
        1. 密码必须由数字、字母及特殊字符三种组合
        2. 密码只能由字母开头
        3. 密码长度不能低于16位'")
        break
  • 相关阅读:
    mysql的一些不常用语句
    redis的使用1
    linux理论知识点(用于考试)
    服务器负载均衡数据同步的实现
    解决com.ibatis.sqlmap.client.SqlMapException: There is no statement named in this SqlMap
    cvc-complex-type.2.3: Element 'beans' cannot have character [children]
    Oracle11g服务详细介绍及哪些服务是必须开启的
    Oracle
    oracle 帐号scott被锁定 如何解锁
    记录
  • 原文地址:https://www.cnblogs.com/themost/p/6358887.html
Copyright © 2011-2022 走看看