Random Password Generator using Python Random

Random Password are very common to all of us, These passwords are generated by all the applications when we request for a new account or request for a new password.

Random Password Generator program written in python is basically used to generate a random password that generate a Good password. This password contains

  1. One captal letter
  2. One small letter alphabet
  3. One Number from 0-9
  4. One special chars like !@#$%^&*()_+>{: etc

The program imports random python module and deploy choice function to choose a single char from a group of chars. This type of selecting a single char was not available in any other high level programming language.

Here is the python source code for generating a standard Password.

#   Objective   : Program to generate a random password using random.choice function
#   made by     : rakesh kumar
#   License     : MIT

import random
chars ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+}{"
length = int(input("Enter password length "))
for i in range(length+1):
    password += random.choice(chars)

# Sample output :
# Enter password length 8
# l#9RX!ufa

The above code ask user to input the length of password and then this length is passed in the range function that is controlled by a for loop. This loop keep on that randomly selected char in our password variable.

Hope you would like this code. if you have any other better idea for generating a better password then kindly let us know.

Author: rakesh kumar

cbsetoday.com is my online home, here I share all the information related to education, programming - and everything else that attract me. You can get in touch with me in these social sharing websites

Leave a Reply