Python Forum
Trying to make a password generator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to make a password generator
#1
I'm trying to make a password generator that restarts if you're not satisfied with your password. The generator itself works perfectly, but when I try to add an input function after the while loop (ques2) it doesn't work. How do I fix this?

import random

chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456!@#$%^&"

ques = input("Do you want a new password? ")

if ques=="yes":
    while 1:
        password_len = int(input("What lenght would you like your password to be : "))
        password_count = int(input("How many passwords would you like :"))
        for x in range (0,password_count):
            password = ""
            for x in range(0, password_len):
                password_char = random.choice(chars)
                password = password + password_char
            print("Here is your password: ", password)
            ques2 = input("Are you satisfied with your password? ")
else:
    print("Okay, goodbye")
deanhystad write Aug-06-2023, 01:08 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Your problem is this:
while 1:
This loop will run forever. You need a way to break out. You also only ask this question once.
ques = input("Do you want a new password? ")
You should break your code up into two parts, one that makes the password, and one that manages the user interface. The password code makes one password. It verifies that the user likes the password, and returns the new password. The user interface is the part that asks the user how long the password should be, calls the function to make the password, and then asks the user if they want another password.

This leaves out the password generation part to focus on the user interface part.
def password(length):
    print("password")

while True:
    password(int(input("What lenght would you like your password to be : ")))
    if input("Do you want a new password? ").lower() != "yes":
        break
print("Okay, goodbye")
Usually password generators have rules such as "At least 1 upper and lower case letter" etc...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to make bot that sends instagram auto password reset code kraixx 2 1,468 Mar-04-2023, 09:59 PM
Last Post: jefsummers
  help me to make my password list in python >>> Oktay34riza 0 605 Dec-23-2022, 12:38 PM
Last Post: Oktay34riza
  how to make my function be a generator Skaperen 2 2,073 Jan-27-2020, 01:07 AM
Last Post: Skaperen
  Random Password Generator with Weird Output. Why? Selenestica 2 2,645 Sep-11-2019, 04:36 AM
Last Post: Selenestica
Photo [split] Password Generator Fusion777 2 2,428 Jul-08-2018, 09:27 PM
Last Post: MasterGame
  receive from a generator, send to a generator Skaperen 9 5,607 Feb-05-2018, 06:26 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020