BUILD A STRONG PASSWORD GENERATOR IN MINUTES
Ever wondered as a newbie programmer how those password generators you see on some web apps and sites are designed? Well..in this post we are going to code a strong password generator with python, and am sure by the end you’ll have a clue how it’s done and even play around with it.
ANY REQUIRED PRIOR KNOWLEDGE?
What’s required here is not much, once you already know the basics of python like lists, string, for loop and etc, then this should fun😆
WHAT YOU WILL LEARN IN THIS TUTORIAL
- How to use the random, string and sleep from time library.
- How to get information from user and assign them to variables
- Using of for loops, .join() method and more..
# let's import the python libraries we'd need
from time import sleep
# let's get user preferences
print('Welcome to Techswitch!🤗')
letter_limit = int(input('How many letters do you want on your password:\n'))
symbol_limit = int(input('How many symbols do you want on your password:\n'))
num_limit = int(input('How many numbers do you want on your password:\n'))
# let's create a list of uppercase and lowrcase strings
letters = list(string.ascii_lowercase + string.ascii_uppercase)
#let's create an empty password list
password = 
#now let's add random user preferred string limit
for chars in range(letter_limit):
password += random.choice(letters)
#now let's add random user preferred punctuation limit
for chars in range(symbol_limit):
#now let's add random user preferred number limit
for chars in range(num_limit):
#let's create a variable called delay
delay = 0.10
#let's shuffle the password list
# let's join the characters in the list to make a decent password
new_password = ''.join(password)
#now let's have some fun and print the password with swag by using sleep module
print('Congratulations! Your new password is:')
for letters in new_password:
print(letters, end = '', flush = True)
So expected output will be something like the result below:
Welcome to Techswitch!🤗
How many letters do you want on your password:
How many symbols do you want on your password:
How many numbers do you want on your password:
Congratulations! Your new password is:
So firstly we imported random, string and sleep from time library, we used random to randomize the user preferred number of letters, numbers and symbols to use in password, and also to shuffle the password lastly to avoid pattern prediction.
We used string library to create a list of lower and upper case alphabets, numbers and punctuation which are to be used in generating a strong password.
Thirdly we had to randomly get the user preferred number of letters, numbers and symbols to make the password
Furthermore we had to create an empty list(the password variable) and append the user derived preferences to it(Randomly).
Lastly we shuffled and joined the passwords together and used print, for loop, and sleep to print out the password to the user in a fun way. You may google about “print” features to learn more about flush, end and etc.
This is a medium difficulty level code for newbies in python, password generators can be created in a different ways using different libraries and codes. Hope you enjoyed the short tutorial. If you are a python newbie and you don’t understand some of the codes used, you can google the keywords of those ones you don’t understand or you can simply write me HERE. You may also stay connected with our updates on our telegram channel.
To run and see this code in action click here. In case you are also replit, you can fork the code and play around with it.