In this project, we will learn how to generate a password using python. We use the "random" function in this code.
Description:
Code:
#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)
# 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 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:
Submitted by Chereddy Vivek Reddy (Vivek)
Download packets of source code on Coders Packet
Comments