Create Random Password Generator Program Using Python

Cyberattacks are growing daily with current statistics stating that about 2,200 attacks are launched each day. That means every 39 seconds, the big bad hacker tries to get into your account.

Hackers mostly get into accounts by cracking the password as they leverage computer programs that are able to generate hundreds of password combinations within seconds. So, if you’re using a simple password, then it can be cracked instantly.

  • Listing all character combinations that are allowed for passwords including letters, numbers, and symbols.
  • Allowing users to customize the generated password by letting them choose how many letters, symbols, and numbers to include.
  • Making it difficult to guess by arranging the characters in a random order.

Developing the random password generator

The above steps form a wireframe of the approach. However, the first step in learning Python programming for kids to code a random password generator is to write the Script.

Create a new file, main.py, to write the scripts for the app.

 

# main.py

letters = [

‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’,

‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’, ‘A’, ‘B’, ‘C’, ‘D’,

‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’, ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’,

‘T’, ‘U’, ‘V’, ‘W’, ‘X’, ‘Y’, ‘Z’

]

numbers = [‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’]

symbols = [‘!’, ‘#’, ‘$’, ‘%’, ‘&’, ‘(‘, ‘)’, ‘*’, ‘+’]

 

print(“Welcome to the PyPassword Generator!”)

 

nr_letters = int(input(“How many letters would you like in your password?\n”))

 

nr_symbols = int(input(f”How many symbols would you like?\n”))

nr_numbers = int(input(f”How many numbers would you like?\n”))

The password generator shown in a list is composed of the characters from the code block above.

The next step is to ensure that users can input a figure, which is an integer that indicates how many times a character will appear in the final output that is declared with a variable and displayed.

n: Indicate that the value entered will be sent to the next line.

Let’s now update the remaining code. Use the undermentioned code for updating.

 

# main.py

letters = [

‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’,

‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’, ‘A’, ‘B’, ‘C’, ‘D’,

‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’, ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’,

‘T’, ‘U’, ‘V’, ‘W’, ‘X’, ‘Y’, ‘Z’

]

numbers = [‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’]

symbols = [‘!’, ‘#’, ‘$’, ‘%’, ‘&’, ‘(‘, ‘)’, ‘*’, ‘+’]

 

print(“Welcome to the PyPassword Generator!”)

 

nr_letters = int(input(“How many letters would you like in your password?\n”))

 

nr_symbols = int(input(f”How many symbols would you like?\n”))

nr_numbers = int(input(f”How many numbers would you like?\n”))

The password generator shown in a list is composed of the characters from the code block above.

The next step is to ensure that users can input a figure, which is an integer that indicates how many times a character will appear in the final output that is declared with a variable and displayed.

n: Indicate that the value entered will be sent to the next line.

Let’s now update the remaining code. Use the undermentioned code for updating.

# main.py

# Password Generator Project

import random # add this

# letters, numbers, and symbols lists

# users’ input for the amount of characters

# add these below

password_list = []

for char in range(1, nr_letters + 1):

    password_list.append(random.choice(letters))

for char in range(1, nr_symbols + 1):

    password_list.append(random.choice(numbers))

for char in range(1, nr_numbers + 1):

    password_list.append(random.choice(symbols))

random.shuffle(password_list)

 

The above code block will enable:

Bringing in the built-in random module to produce random numbers.

Make a blank list [] using the password_list variable.

Create a series of numbers starting at the start index and ending with the last index plus one by iterating through the numbers in the range function.

Next, append the empty list to each of the character’s declared variables in order to obtain a randomly chosen element using the random.choice() method.

Using the, shuffle the newly generated password_list, shifting the elements’ positions each time a new password is entered.shuffle() technique

Once all is set, run the program to generate your random passwords.

Learning Python programming for kids is easy and becomes fun with SCRATCHPAD. The experts implement the best ways to help kids learn Python including interactive sessions too.