gpt4 book ai didi

python - 我怎样才能让我的程序返回密码强度

转载 作者:太空宇宙 更新时间:2023-11-04 10:08:02 24 4
gpt4 key购买 nike

我正在努力使用我的密码评估程序。我怎样才能确保当我输入密码时,我的程序返回密码强度。当我运行这个程序时,它说 password_strength 存储在 .....) 是我在程序结束时调用的返回错误吗?

print ("Welcome to this password rater program")
print ("Your password needs to have a minimum of 6 characters with a maximum of 20 characters.")
print ("Your password can contain lowercase and uppercase characters, numbers and special characters")
print("")


password = input("Please insert your password: ")


def check_len(password):
l = len(password)
if 6 < l < 20:
x = check_char(password, l)
else:
x = 0
return x


def check_char(password, l):
for i in range(l):
ascii = ord(password[i])
num = 0
upper = 0
symbols = 0
lower = 0
space = 0

if 96 < ascii < 123:
lower = 15
elif 47 < ascii < 58:
num = 25
elif 64 < ascii < 91:
upper = 25
elif ascii == 32:
space = 30
else:
symbols = 25
total = ((lower + num + upper + space + symbols) * len(password))
return total


def password_strength(total):
if total >= 1000:
print("Your chosen password is Very strong")
elif 700 < total < 999:
print("Your chosen password is strong")
elif 500 < total < 699:
print("your chosen password is medium")
elif total <= 500:
print("Your chosen password is weak")
return total


strength = check_len(password)
print(password_strength(strength))

最佳答案

首先,您告诉 python 打印函数,而不是函数的求值。这就是您收到该消息的原因。

此外,您永远不会调用您编写的任何函数。获得一个工作程序所有定义声明后如下:

调用 check_len 定义:

strength = check_len(password)

虽然这个定义不返回任何值。您可以将其更改为:

def check_len(password):
l = len(password)
if 6 < l < 16:
x = check_char(password, l)
else:
x = 0
return x

让它返回分数/强度。

最后,您应该使用“password_strength”定义来处理分数:

password_strength(strength)

这一行不需要打印,因为打印语句在定义本身。但是,如果您还想打印最终分数,可以将其放入以下行:

 print(password_strength(strength))

还有一个调试问题:您的 check_char 定义不带任何参数。您可以通过将其更改为:

def check_char(password, l):

最终代码: 打印(“欢迎使用此密码评估程序”) print ("您的密码需要最少 6 个字符,最多 16 个字符。") print("您的密码可以包含大小写字符、数字和特殊字符") 打印(“”)

password = raw_input("Please insert your password: ")


def check_len(password):
l = len(password)
if 6 < l < 16:
x = check_char(password, l)
else:
x = 0
return x


def check_char(password, l):
for i in range(l):
ascii = ord(password[i])
num = 0
upper = 0
symbols = 0
lower = 0
space = 0

if 96 < ascii < 123:
lower = 15
elif 47 < ascii < 58:
num = 25
elif 64 < ascii < 91:
upper = 25
elif ascii == 32:
space = 30
else:
symbols = 25
total = ((lower + num + upper + space + symbols) * len(password))
return total


def password_strength(total):
if total >= 1000:
print("Your chosen password is Very strong")
elif 700 < total < 999:
print("Your chosen password is strong")
elif 500 < total < 699:
print("your chosen password is medium")
elif total <= 500:
print("Your chosen password is weak")
return total


strength = check_len(password)
print(password_strength(strength)) `

关于python - 我怎样才能让我的程序返回密码强度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39913740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com