Advertisement
jimboulton

Password generator

Mar 8th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. # Passwords generator
  2. # Initialise characters for password
  3. from random import choice
  4. alpha = ("abcdefghijklmnopqrstuvwxyz")
  5. nos = ("0123456789")
  6. symbols = ("!?#$£%&")
  7. chset = ("012")
  8. password = ['.','.','.','.','.','.','.','.']
  9. #
  10. def gen_password():
  11. noofchars = int(input("How many characters do you require - max 8 "))
  12. # noofchars = int(noofchars)
  13. if noofchars > 8:
  14. noofchars = 8
  15. print ("password length " + str(noofchars))
  16. # generate password
  17. for i in range (0, noofchars):
  18. # find a random character from alpha, nos, symbols
  19. rand = int(choice(chset))
  20. if rand == 0:
  21. character = choice(alpha)
  22. if rand == 1:
  23. character = choice(nos)
  24. if rand == 2:
  25. character = choice(symbols)
  26. password[i] = character
  27. # print password
  28. print ("password of " + str(noofchars) + " chars = ")
  29. for i in range (0, noofchars):
  30. print (password[i])
  31. print ("bye")
  32.  
  33. gen_password()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement