Advertisement
SavannahU

password generator

Mar 11th, 2020
2,470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. # imports random module from the library
  2. import random
  3. # create a list of possible characters
  4. characters = ["1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
  5.  
  6. # define a function to generate a password
  7. def generate_password(pwd_length):
  8.     # sets up an empty list to store the password that will be created
  9.     password = []
  10.     # set up a for loop to iterate for how many characters are needed in the password
  11.     for x in range (pwd_length):
  12.         # select a random item from the characters list
  13.         newItem = random.choice(characters)
  14.         # add that item to the password list
  15.         password.append(newItem)
  16.     # return all the new items in the password list joined together in one string
  17.     return ''.join(password)
  18.  
  19. # ask the user to specify the length of their password
  20. psw_length = int(input("Please enter the length of your password "))
  21. # set the password from the output of the generate_password function
  22. password = generate_password(psw_length)
  23. # output the generated password
  24. print (password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement