正在尝试创建一个可以保存密码的密码生成器



我已经创建了该程序的基线,它运行良好,但我希望它能够保存密码生成,并将它们存储在SQLite的索引名称下。我希望它是这样,我可以随时访问以前生成的密码。

代码:

def gen_password():
letters = string.ascii_letters
random_letter = random.choice(letters)
random_num = random.randint(0,9)
letter_or_num = ["letter","number"]
char_num = int(input("How many characters do you want in your password?: "))
for i in range(char_num):
random_var = random.choice(letter_or_num)
if random_var == "letter":
random_letter = random.choice(letters)
print(random_letter, end = "")
elif random_var == "number":
random_num = random.randint(0,9)
print(random_num, end = "")
print("")

gen_password()

我希望这能解决你的问题:

def gen_password():
letters = string.ascii_letters
random_letter = random.choice(letters)
random_num = random.randint(0,9)
letter_or_num = ["letter","number"]
char_num = int(input("How many characters do you want in your password?: "))

password = []
for i in range(char_num):
random_var = random.choice(letter_or_num)
if random_var == "letter":
random_letter = random.choice(letters)
# replace print with this:
password.append(random_letter)  

elif random_var == "number":
random_num = random.randint(0,9)
password.append(str(random_num))
return "".join(password)
print(gen_password())

相关内容

  • 没有找到相关文章

最新更新