Create a Random Password Generator using Python

Search for a command to run...

Hey everyone! All of the dnp capstone experts on our team are pre-screened and have at least 1+ years of experience in helping students achieve academic success. See how we select our employees.
The series content will mostly cover Technical Python tutorials and my recent learnings and experience in Python.
Hello world! IP address helps in connecting our computer to other devices on our network and all over the world. In this Blog article, we will learn how to Find IP Address of any Website. We will see the implementation in Python. Check out the Reposi...
All you need to know about Hacktoberfest 2021

Hello reader! Well, Hacktoberfest is something, you are gonna hear a lot about in the coming month. You can refer to my YouTube video Tutorial to see a working tutorial for better understanding and a step-by-step guide of the same. https://www.yo...

Hello reader! In this Blog post, I will share some useful code snippets and functions in Python. Give it a read. Let's get started! 1. Memory The method getsizeof can be used to retrieve the size of any object. Here's an example of the same. import...

Hello reader! Whenever a client sends a request to the server, the response always contains a status code. You might not see it always but it's returned at every client-server interaction. Well, even if you are not a programmer, you would still know...

Hello reader! Microsoft subsidiary GitHub launched Copilot to power pair programming with AI. In this blog post, I will share all you need to know about it. You can refer to my YouTube video Tutorial to see a working tutorial for better understandin...

Hello world!
We all make use of passwords on a daily basis, to keep your account safe and prevent your password from being hacked we have to make our password is hard enough that nobody can guess.
Password generator is a Random Password generating program which generates a password mix of upper and lowercase letters, as well as numbers and symbols strong enough to provides great security.
In this Blog article, we will learn how to Create a Random Password Generator. We will see the implementation in Python.
Check out the Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a PR on the same!
You can refer to my YouTube video Tutorial to see a working tutorial for better Understanding and a step by step Guide of the same.
1. What is Password
2. Random and String Module
3. how to Create a Random Password Generator
Let's get started!
A password, sometimes called a passcode, is a memorized secret, typically a string of characters, usually used to confirm the identity of a user, In other words is a string of characters used to verify the identity of a user during the authentication process.
If you wish to know more about it, you can refer to Password Wikipedia Page.
Random module is used to perform the random generations. We are making use of random.sample module here. If you will observe in the output all characters will be unique. random.sample() never repeats characters. If you don’t want to repeat characters or digits in the random string, then use random.sample() but it is less secure because it will reduce the probability of combinations because we are not allowing repetitive letters and digits.
The string module contains a number of useful constants, classes and a number of functions to process the standard python string.
string.ascii_letters: Concatenation of the ascii (upper and lowercase) lettersstring.ascii_lowercase: All lower case lettersstring.ascii_uppercase: All Upper case lettersstring.digits: The string ‘0123456789’.string.punctuation: String of ASCII characters which are considered punctuation characters in the C
locale.Now that you are familiar with password use cases and have acquired basic knowledge of random and string module, we can move forward to the coding section.
You can find all the code at my GitHub Repository. Drop a star if you find it useful.

In order to access the Python library, we need to import the package in our Python script.
import random
import string
Once done, let's greet the user!
print('hello, Welcome to Password generator!')
Next, let's ask the user for the length of the password.
length = int(input('\nEnter the length of password: '))
Its time to define the data. We will make use of string module for the same.
lower = string.ascii_lowercase
upper = string.ascii_uppercase
num = string.digits
symbols = string.punctuation
We have stored lowercase and uppercase letters along with numbers and symbols. Let's combine the data and store the data.
all = lower + upper + num + symbols
Now that we have the data, let's make use of random module to finally generate the password.
temp = random.sample(all,length)
password = "".join(temp)
We are passing in the the combined data along with the length of password, and joining them at the end.
Now that you have a clear understanding of the script, we can even reduce the number of lines of code by eliminating the storage of data. Let's have a look.
all = string.ascii_letters + string.digits + string.punctuation
pass = "".join(random.sample(all,length))
Finally, let's print the password!
print(password)
Let's have look at few sample outputs:
#SAMPLE O/P: (length = 16)
3Atza*qP#h-vJoK+
7c%A4gOt#M[}qr2
@JmFf"awbQ1Ts4dx
With these steps, we have successfully created a random password generator project using python. That's it!
Simple, isn't it? Hope this tutorial has helped. I would strongly recommend you to Check out the YouTube video of the same and don't forget to subscribe my Channel.
You can play around with the Instaloader library and even explore more features. You can even make use of Python GUI using Tkinter.
You can find all the code at my GitHub Repository. Drop a star if you find it useful.
Thank you for reading, I would love to connect with you at Twitter | LinkedIn.
Do share your valuable suggestions, I appreciate your honest feedback!
You should definitely check out my other Blogs:
See you in my next Blog article, Take care!!