Password Generator


We all use passwords to keep our account safe and secure so that it can be prevented from being attacked, but how can we achieve this? In order to make our password safe and secure, we need to use a password that can’t be guessed easily.

As per sources nearly 81% of online attacks are password related due to the poor password habits such as using a common password for different accounts, sharing credentials, and easily predictable password.

How can we create a strong password that is not easily guessable? There are several standards we need to follow.

  1. Inclusion of both upper-case and lower-case letters
  2. Inclusion of one or more numerical digits
  3. Inclusion of special characters such as @, #, $
  4. Prohibition of names, phone numbers, plate numbers
  5. Prohibition of personal information.

By Following this policy, we can set the strongest password that no one can guess.

Enough of lengthy definitions and descriptions. Let’s see how we can implement this in Python!!

For this, I have used two modules available from Python. They are

  • Random Module.
  • Array Module.

First things first, let’s import the two modules.

import random
import array

Next, we need to get the maximum length of the password from the user.

MAX_LEN = int(input("Enter the length of the Password : "))

Creating an Array to store the Alphanumeric characters and Symbols.

Combining the arrays and store it in a single variable.

combinedList= digits + upcaseCharacters + locaseCharacters + symbols

Next, randomly choosing one character from the array we just created.

randDigit = random.choice(digits)
randUpper = random.choice(upcaseCharacters)
randLower = random.choice(locaseCharacters)
randSymbol = random.choice(symbols)

Now, we create a temporary variable and add the randomly chosen Characters.

tempPass = randDigit + randUpper + randLower + randSymbol

Now we have random characters with the length of 4. To achieve the length we just got from the user, We are going to fill the list with random characters from the CombinedList variable.

Now we traverse the temp password array and append the characters and finally print the Password we generated.

Sample Input :
Enter the length of the password : 8
Sample Output:

The output gets varied each and every time you run the code with different possibilities and Thats all folks! we just implemented a strong password generator using python.

You can find the whole code in my Github Repository. Drop a star if you find it useful.

You can play around and even explore more features. You can even make use of Python GUI using Tkinter.

Thanks for Reading, and do checkout my other blog


See you in next blog Article. Take Care




Student | Motorsports Enthusiast | Ferrari Tifosi | Dev

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

DevSecops — Integrating Security into the DevOps Process

Effective Switching of Enums

Building a Rejection Hotline with Twilio for Peach PRC

Which Are the Top 5 Python Libraries Used for Web Scraping?

Dare mighty things — ASCII

Weeknote w/c 8 April — w/c 22 April: Easter comes and goes

Deadlines Without Estimates

Creating (almost) perfect Hackintosh VM

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Student | Motorsports Enthusiast | Ferrari Tifosi | Dev

More from Medium

Uninstall MySQL and Install MariaDB 10.7 on Ubuntu 18.04

How to detect an object without OpenCV in Webots?

Customize your command line interface in Python

Command line

Industry 4.0 : integration with IOT