Password Generator

Password Generator

 

GROUP NAME:  Computer   Nerds

Create a Random Password Generator using Python


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.

We will learn how to Create a Random Password Generator. We will see the implementation in Python.

Let’s get started!

What is Password:

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.

Modules Used:

Random Module:

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.

String Module:

The string module contains a number of useful constants, classes and a number of functions to process the standard python string.

1.     string.ascii_letters: Concatenation of the ascii (upper and lowercase) letters

2.   string.ascii_lowercase: All lower case letters

3.    string.ascii_uppercase: All Upper case letters

4.   string.digits: The string ‘0123456789’.

5.    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.

Time to Code!

 











In order to access the Python library, we need to import the package in our Python script.

import random
import string

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 combined data along with the length of the 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.

 

With these steps, we have successfully created a random password generator project using python. That’s it!

 

Let’s have look at few sample outputs:

#SAMPLE O/P: (length = 6)

Dr5@"t

2R8)?t

#SAMPLE O/P: (length = 8)

{RfGSKat

CN67V<eF

#SAMPLE O/P: (length = 16)

^{U2)~[vlc>&:rxp

B'ftHc?lD7XK!;g[

No comments

Powered by Blogger.