Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中检查字符串中有多少个数字?(密码强度检查器)_Python - Fatal编程技术网

如何在python中检查字符串中有多少个数字?(密码强度检查器)

如何在python中检查字符串中有多少个数字?(密码强度检查器),python,Python,我正在做一个密码强度检查作为一个学校项目,但我正在努力找到一种方法来检查密码中有多少个整数,因此我在三件事上检查密码,但我就是不知道如何检查整数。如果你们能帮助我的解决方案可以包括re库,那会更好。谢谢 这是我到目前为止有问题的代码 import re i_pwdStrength = i_pwdLength + i_pwdChar + i_pwdInt i_pwdLength = 0 i_pwdChar = 0 i_pwdInt = 0 i_at

我正在做一个密码强度检查作为一个学校项目,但我正在努力找到一种方法来检查密码中有多少个整数,因此我在三件事上检查密码,但我就是不知道如何检查整数。如果你们能帮助我的解决方案可以包括re库,那会更好。谢谢

这是我到目前为止有问题的代码

    import re

    i_pwdStrength = i_pwdLength + i_pwdChar + i_pwdInt
    i_pwdLength = 0
    i_pwdChar = 0
    i_pwdInt = 0
    i_attempts = 0
    numbAttemps = int(input("Enter the amount of passwords you would like to check \n(MUST BE A NUMBER)"))
    pwd = input("Enter Password")


    while numbAttempts < i_attempts
        pwd = pwd.lower()

    i_pwdLength = pwd.length
    if i_pwdLength <= 3:
        i_pwdLength = 1
    elif i_pwdLength > 3 && <= 6:
        i_pwdLength = 2
    elif i_pwdLength > 6 && <= 9:
        i_pwdLength = 3
    else i_pwdLength > 9:
        i_pwdLength = 4

    i_pwdChar =      #This is a very long way of writing this code as I could not find a way to compress these lines. I may have used the 'or' command but I could not
    if re.search(r'[x]',pwd):              # work out how to integrate it and i thought that this code looked neater
        i_pwdChar = 1
    elif re.search(r'[w]'pwd):
        i_pwdChar = 1
    elif re.search(r'[y]'pwd):
        i_pwdChar = 1
    elif re.search(r'[z]'pwd):
        i_pwdChar = 1
    elif re.search(r'[x]',pwd) and re.search(r'[w]',pwd):
        i_pwdChar = 2
    elif re.search(r'[x]',pwd) and re.search(r'[y]',pwd):
        i_pwdChar = 2
    elif re.search(r'[x]',pwd) and re.search(r'[z]',pwd):
        i_pwdChar = 2
    elif re.search(r'[w]',pwd) and re.search(r'[y]',pwd):
        i_pwdChar = 2
    elif re.search(r'[w]',pwd) and re.search(r'[z]',pwd):
        i_pwdChar = 2
    elif re.search(r'[y]',pwd) and re.search(r'[z]',pwd):
        i_pwdChar = 2
    elif re.search(r'[w]',pwd) and re.search(r'[x]',pwd) and re.search(r'[y]',pwd):
        i_pwdChar = 3
    elif re.search(r'[z]',pwd) and re.search(r'[x]',pwd) and re.search(r'[y]',pwd):
        i_pwdChar = 3
    elif re.search(r'[w]',pwd) and re.search(r'[z]',pwd) and re.search(r'[y]',pwd):
        i_pwdChar = 3
    else re.search(r'[w]',pwd) and re.search(r'[x]',pwd) and re.search(r'[y]',pwd) and re.search(r'[z]',pwd)
        i_pwdChar = 4
重新导入
i_pwdStrength=i_pwdLength+i_pwdChar+i_pwd力
i_pwdLength=0
i_pwdChar=0
i_pwdInt=0
i_=0
numbAttemps=int(输入(“输入要检查的密码数量(必须是数字)”)
pwd=输入(“输入密码”)
当尝试
由于我得到的所有帮助,我已经完成了代码

    import re

    i_numbAttempts = int(input("How many passwords do you want to try?\nMUST BE A NUMBER!")) # Determines how many times the while loop further down
    attempts = 0    # sets the variable attempts to 0 to ensure that the while loop works                # repeats itself

    while i_numbAttempts > attempts:      # while the passwords entered is more than attempts:
        pwd = input("Enter Password: ")   # user enters password to check
        pwd = pwd.lower()                 # sets the password to lowercase (QjwtwWyeRvgTRDU would become qjwtwwyervgtrdu)

        if len(pwd) == 0:                        # if the user does not enter a password, it outputs: You must ypre something!
            print("You must type something!")
            i_pwdLength = 0
        elif len(pwd) >= 1 and len(pwd) <= 3:    # if the length is a certain length,
            i_pwdLength = 1                      # it will assign a corresponding value to the i_pwdLength variable
        elif len(pwd) > 3 and len(pwd) <= 6:     
            i_pwdLength = 2
        elif len(pwd) > 6 and len(pwd) <= 9:
            i_pwdLength = 3
        elif len(pwd) > 9:
            i_pwdLength = 4

        if re.search(r'[w]',pwd) and re.search(r'[x]',pwd) and re.search(r'[y]',pwd) and re.search(r'[z]',pwd):
            i_pwdChar = 4
        elif re.search(r'[w]',pwd) and re.search(r'[x]',pwd) and re.search(r'[y]',pwd):
            i_pwdChar = 3
        elif re.search(r'[z]',pwd) and re.search(r'[x]',pwd) and re.search(r'[y]',pwd):
            i_pwdChar = 3
        elif re.search(r'[w]',pwd) and re.search(r'[z]',pwd) and re.search(r'[y]',pwd):
            i_pwdChar = 3
        elif re.search(r'[w]',pwd) and re.search(r'[x]',pwd) and re.search(r'[y]',pwd) and re.search(r'[z]',pwd):
            i_pwdChar = 4
        elif re.search(r'[x]',pwd) and re.search(r'[w]',pwd):              # This section checks the password for any 
            i_pwdChar = 2
        elif re.search(r'[x]',pwd) and re.search(r'[y]',pwd):               # Combination of the letters w,x,y and z.
            i_pwdChar = 2
        elif re.search(r'[x]',pwd) and re.search(r'[z]',pwd):               # I could not find a way to compress these
            i_pwdChar = 2
        elif re.search(r'[w]',pwd) and re.search(r'[y]',pwd):               # Lines so i left them as is as i thought
            i_pwdChar = 2
        elif re.search(r'[w]',pwd) and re.search(r'[z]',pwd):               # That it looked neater
            i_pwdChar = 2
        elif re.search(r'[y]',pwd) and re.search(r'[z]',pwd):
            i_pwdChar = 2
        elif re.search(r'[x]',pwd):
            i_pwdChar = 1
        elif re.search(r'[w]',pwd):
            i_pwdChar = 1
        elif re.search(r'[y]',pwd):
            i_pwdChar = 1
        elif re.search(r'[z]',pwd):
            i_pwdChar = 1
        else:
            i_pwdChar = 0

        if (len([l for l in pwd if l.isdigit()])) == 0:                                                     # This code checks how many integers are included
            i_pwdInt = 0
        elif (len([l for l in pwd if l.isdigit()])) >= 1 and (len([l for l in pwd if l.isdigit()])) < 3:    # In the password, and assigns a number to the 
            i_pwdInt = 1
        elif (len([l for l in pwd if l.isdigit()])) >= 3 and (len([l for l in pwd if l.isdigit()])) < 5:    # Variable i_pwdInt accordingly
            i_pwdInt = 2
        elif (len([l for l in pwd if l.isdigit()])) >=5 and (len([l for l in pwd if l.isdigit()])) <7:
            i_pwdInt = 3
        elif (len([l for l in pwd if l.isdigit()])) >=7:
            i_pwdInt = 4

        i_pwdStrength = i_pwdLength + i_pwdChar + i_pwdInt     # this determines the passwords overall strength

        if i_pwdStrength > 0 and i_pwdStrength <= 4 :
            print("This password is bad")
        elif i_pwdStrength > 4 and i_pwdStrength <= 8:
            print("This password is OK")
        elif i_pwdStrength > 8 and i_pwdStrength <= 11:
            print("this password is good")
        elif i_pwdStrength == 12:
            print("this password is the best!!")

        attempts = attempts + 1
重新导入
i_numbtemptures=int(输入(“您想尝试多少密码?\n必须是一个数字!”)#确定while循环向下的次数
尝试次数=0#将变量尝试次数设置为0,以确保while循环工作#重复自身
while i_numberAttempts>attempts:#当输入的密码超过尝试次数时:
pwd=输入(“输入密码”)#用户输入密码进行检查
pwd=pwd.lower()
如果len(pwd)=0:#如果用户没有输入密码,它会输出:您必须输入一些东西!
打印(“您必须键入内容!”)
i_pwdLength=0
如果len(pwd)>=1和len(pwd)3以及len(pwd)6和len(pwd)9:
i_pwdLength=4
如果重新搜索(r'[w]',pwd)和重新搜索(r'[x]',pwd)以及重新搜索(r'[y]',pwd)和重新搜索(r'[z]',pwd):
i_pwdChar=4
elif检索(r'[w]',pwd)和检索(r'[x]',pwd)以及检索(r'[y]',pwd):
i_pwdChar=3
elif检索(r'[z]',pwd)和检索(r'[x]',pwd)以及检索(r'[y]',pwd):
i_pwdChar=3
elif检索(r'[w]',pwd)和检索(r'[z]',pwd)以及检索(r'[y]',pwd):
i_pwdChar=3
elif检索(r'[w]',pwd)和检索(r'[x]',pwd)以及检索(r'[y]',pwd)和检索(r'[z]',pwd):
i_pwdChar=4
elif re.search(r'[x]',pwd)和re.search(r'[w]',pwd):#本节检查密码是否存在任何错误
i_pwdChar=2
elif检索(r'[x]',pwd)和检索(r'[y]',pwd):#字母w、x、y和z的组合。
i_pwdChar=2
elif re.search(r'[x]',pwd)和re.search(r'[z]',pwd):#我找不到压缩这些数据的方法
i_pwdChar=2
elif re.search(r'[w]',pwd)和re.search(r'[y]',pwd):#行,所以我按我的想法保留了它们
i_pwdChar=2
elif重新搜索(r'[w]',pwd)和重新搜索(r'[z]',pwd):#它看起来更整洁
i_pwdChar=2
elif检索(r'[y]',pwd)和检索(r'[z]',pwd):
i_pwdChar=2
elif检索(r'[x]',pwd):
i_pwdChar=1
elif检索(r'[w]',pwd):
i_pwdChar=1
elif检索(r'[y]',pwd):
i_pwdChar=1
elif检索(r'[z]',pwd):
i_pwdChar=1
其他:
i_pwdChar=0
if(len([l代表pwd中的l if l.isdigit()])==0:#此代码检查包含多少个整数
i_pwdInt=0
密码中的elif(len([l代表pwd中的l,如果l.isdigit()])>=1和(len([l代表pwd中的l,如果l.isdigit()]))<3:#,并为
i_pwdInt=1
elif(len([l代表pwd中的l,如果l.isdigit()])>=3和(len([l代表pwd中的l,如果l.isdigit()]))<5:#相应的变量i
i_pwdInt=2
elif(len([l代表pwd中的l,如果l.isdigit()])>=5和(len([l代表pwd中的l,如果l.isdigit()]))=7:
i_pwdInt=4
i_pwdStrength=i_pwdLength+i_pwdChar+i_pwdInt#这决定了密码的整体强度
如果i_pwdStrength>0,i_pwdStrength 4,i_pwdStrength 8,i_pwdStrength我想你应该使用这个方法。以下命令将返回密码中的位数

len([l for l in pwd if l.isdigit()])

计算通行证的更好方法