Password generator in Python
In this project, we will learn how to generate a password using python. We use the "random" function in this code.
Description:
- The Python code in the packet is used to generate a password in a particular format.
- Format of the password is :
"Company name"+"@"+"random 5 digit number" + "a character " + "one upper case and lower case alphabet"
Code:
- "random" function is used to generate random numbers and alphabets.

- The generated password will be strong because it has 2 special characters, upper and lowers case alphabets and numbers.
- The code takes company name as input and generates a password in the above-given format.
- While using this code, you can give the company name as an argument and it will return a password.
- The Company name is sent as an argument to the function generate_password
#Taking company name as input company_name=input() #calling generate_password function #sending company name as a argument password=generate_password(company_name) print(password)
- code in the generate_password function is explained in pictures below.
# defining generate_password function by taking company name as a argument
def generate_password(company_name):
#First step to create our password:
#adding '@' charecter to company name and now we have a password
password=company_name+'@'
#Second step : adding five random numbers to our present password
#chr is used to show charecter of given ASCII number and
#ASCII numbers of numbers from 0 to 9 are 48 to 57
for i in range(5):
password=password+chr(random.randint(48,57))
- declaring a list named array and appending few characters to our list
#declaring a list named array and appending few charecters to our list array=['!','#','$','%','^','&','*','<','>',':',';','/','-','+','='] #Third step: Adding a charecter to our present password. password=password+array[random.randint(0,len(array)-1)] #Fourt step: Adding a upper case and a lower case alphabet to our present password. #ASCII values of alphabests are as shown 65 to 90 for upper case and 97 to 122 for lower case. password=password+chr(random.randint(65,90)) password=password+chr(random.randint(97,122)) #now we have a password in the format # returning final password return password
Input and Output:

Project Files
/
Loading...
| .. | ||
| This directory is empty. | ||