Project : Password Generator in Python

 

In our daily lives, we need many different types of accounts. In order to set up these accounts we need a password to protect our accounts and it is difficult to manage the passwords of all the accounts differently and this frustrates our mind a lot.

So what if a strong password is automatically generated. That would be very relieving, right!

Then, let’s create a password generator in such interactive language Python. If you don't know the python then don't worry. I will explain to you step by step how to make a project.

STEP 1 :

Python module:

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable __name__.

We use built-in modules in python string and random module.

For more about modules please visit :

Python Modules

STEP 2 :

We want to create a strong password and the key aspects of a strong password are lengths, a mixture of letters (uppercase and lowercase), numbers, and symbols (punctuation). So we include all these things in our project and it is all already in the string module. Just we have to put it in code.

So for this visit :

string — Common string operations 

STEP 3 :

Creating a password requires different preferences of a different person, such as how long the password should be That is why we need to ask the length but wait… If they enter the wrong data type, then.

Hence, we use a try and except for more detail about exceptions:

Errors and Exceptions

STEP 4 :

If we create a password, we need a variable, so that we store that password, so in Python, we have a list, which stores anything we want. For more about the list visit:

Data Structures in Python

STEP 5 :

We use a random module for shuffle the password because in the list we have a sorted elements. For more about visit :

random — Generate pseudo-random numbers

STEP 6 :

At last, we print a password.


CODE:

import string

import random 

if __name__ == '__main__':

    letter_lowercase = string.ascii_lowercase

    letter_uppercase = string.ascii_uppercase

    digits = string.digits

    punctuation = string.punctuation

    while(True):

        try:

            len = int(input("Enter Password Length : "))

            break

        except:

            print("Invalid Numbers")

    password = []

    password.extend(list(letter_lowercase))

    password.extend(list(letter_uppercase))

    password.extend(list(digits))

    password.extend(list(punctuation))

    random.shuffle(password)

    print("Your Password is : ")

    print("".join(password[0:len]))

Output:

Enter Password Length : 7

Your Password is :

_?e:Ffj


Finally, we have created a password generator.

If  this post helpful for you then please like comment & share.

 

Follow us on : 


Email : vsquare

Instragam : vsquare_insta

Facebook : vsquare_fb

Linkedin : vsquare

Website : https://vsquare2028.blogpost.com/

Comments