Yashraj Singh Negi
<Code/Week> with Yashraj


<Code/Week> with Yashraj

10 minutes Python Project: Password Generator

10 minutes Python Project: Password Generator

Easy mini python project to start your programming journey.

Yashraj Singh Negi 's photo
Yashraj Singh Negi
·Mar 12, 2023·

2 min read

Play this article

Hey readers, first of all, sorry that I missed last week's article. I was travelling to new places so I could not get time to learn something new in tech which was the reason why I didn't post the article last week. But don't worry, today I have something which will make your day if you are new to programming, especially Python.

Today, we are going to make an easy Python project which can be made in less than 10 minutes. Of course, this project is not worth adding to your CV or Resume but this project will give you a good experience in learning Python programming. Let's begin!

Many times while signing up for a new application you might have thought a lot about what should be your password and you end up selecting some silly password that may cause you some danger. For this Google has a random password generator function that asks you to automatically generate a strong password consisting of alphabets(small and capital), numbers, alphanumerics etc. and saves it so that you don't need to remember this tough password and also your credentials remain safe. Today we are going to program our password generator.

Making Pieces!

Importing string module to import all the letters, numbers and characters and random module to make a random and strong password.

import string 
import random

Defining generate password function. Generates a random password of the specified length(you can also change the length). Also, we are excluding special characters that can create problems on a web page like <>/{}|* etc. We are mentioning only those characters which are necessary that's why we are not importing punctuation from string module.

def generate_password(length = 8):

    lowercase = string.ascii_lowercase
    uppercase = string.ascii_uppercase
    digits = string.digits
    punctuations = "!#%+:=?@"

    # Combine all characters into a single string
    all_characters = lowercase + uppercase + digits + punctuations

    # Use random.sample to select a random subset of characters
    password_string = random.sample(all_characters, length)

    # Convert the subset back to a string and return
    password = ''.join(password_string)

    return password

And that's all. Just run the following code and you'll get your strong password printed.

# To generate a password of 10 characters

# To generate a password of 12 characters 

# And so on...

Make this mini project using Python and flaunt it in front of your peers. Hope you like this article and don't forget to share it with your friends. Let them also be a part of a weekly learning community.

Don't miss any updates by subscribing to the newsletter (CLICK HERE).

See you next Sunday at 9 am. Till then, keep learning!

Signing off!

Did you find this article valuable?

Support Yashraj Singh Negi by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
Share this