【发布时间】:2020-04-14 17:03:26
【问题描述】:
我想用 Python 构建一个强密码生成器,强密码是 2 个小写字符、2 个大写字符、2 个数字、2 个符号。强大的部分给了我错误。在while中随机调用方法的位置参数太多
# Password generator
import random
import string
def create_waek_pass():
password = random.randint(10000000, 99999999)
print(f"password : {password}")
def create_strong_pass():
password = []
for i in range(2):
lower = [string.ascii_lowercase] # i wanted to create a list with 2 lower case chars
upper = [string.ascii_uppercase]
number = [random.randint(0, 9)]
exclimations = [string.punctuation]
while len(password) <= 8:
password = random.choice(lower, upper, number, exclimations)
print(password)
【问题讨论】:
-
您的代码没有意义。在 for 循环中,您只需使用包含单个事物的列表(例如
['abcdefghijklmnopqrstuvwxyz'])来隐藏相同的名称。然后在整个循环中,您不断尝试 replace 整个密码值。我猜错误是选择只需要一个值,但你有更深层次的算法问题。 -
“强大的部分给了我错误” - 有什么理由不包括该错误的描述?
-
我想创建一个包含从 a 到 z 的 2 个字符的小写列表
-
问题是为什么,看你的代码很清楚你可能没有太多的python经验,所以可能在安全方面的经验更少。所以我想说不要尝试自己编写。有更多的人拥有更丰富的安全知识,所以让他们做这项工作
-
这只是我想为自己做的培训
标签: python python-3.x passwords