A random password generator is used to create a password with a specified number of characters. This code can be generate random passwords that contain alpha-numeric and special characters.
A random password generator has wide-spread applications in the industry today. For accounts to be secure, their passwords must be strong. The strength of a password is determined by the randomness of it. Thus more random the string of characters, more secure the password is.
This code uses the string and random modules to genrate random characters which are then composed into a string and displayed to the user.
The code can be used to generate purely alphabetical passwords, alpha-numeric passwords and alpha-numeric + special character passwords.
Passwords with upper and lower case charatcters.
import random import string def random_password(length): # Random string with the combination of lower and upper case. letters = string.ascii_letters separator = '' password = separator.join(random.choice(letters) for i in range(length)) print("One possible password is:", password) length = int(input("Enter the desired length of the password:")) random_password(length)
Passwords with upper and lower case alphabets and numbers.
import random import string def random_password(length): # Random string with the combination of lower and upper case and numbers. letters = string.ascii_letters + string.digits separator = '' password = separator.join(random.choice(letters) for i in range(length)) print("One possible password is:", password) length = int(input("Enter the desired length of the password:")) random_password(length)
Passwords with upper and lower case alphabets, numbers and special characters.
import random import string def random_password(length): # Random string with the combination of lower and upper case, numbers and special characters. letters = string.ascii_letters + string.digits + string.punctuation separator = '' password = separator.join(random.choice(letters) for i in range(length)) print("One possible password is:", password) length = int(input("Enter the desired length of the password:")) random_password(length)
Submitted by Vishaka Iyengar (reachvishakas)
Download packets of source code on Coders Packet
Comments