IsenfireLDC

Random Password Generator 1: Edits 1 <Fixed>

May 4th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. import math
  2. import random
  3. alpha = ['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']
  4. print('Would you like a random password suggestion generator', 'Yes or No')    #Asks for parameters
  5. permissionRandomGenerator = input().lower()
  6.  
  7. if permissionRandomGenerator == 'yes':    #Initiates password generator
  8.     print('How long do you want your password?')
  9.     lengthRandomGenerator = int(input())
  10.     def randInt():
  11.         return math.floor(random.random()*10)
  12.     def randChar():
  13.         return alpha[math.floor(random.random()*27) - 1]
  14.     randPasswordList = []
  15.     listInsert = 0
  16.     def changeCase(f):
  17.         g = round(random.random())
  18.         if g == 0:
  19.             return f.lower()
  20.         elif g == 1:
  21.             return f.upper()
  22.     while listInsert < lengthRandomGenerator + 1:
  23.         randPasswordList.insert(listInsert, randInt())
  24.         listInsert = listInsert + 1
  25.         if listInsert >= lengthRandomGenerator + 1:
  26.             break
  27.         randPasswordList.insert(listInsert, randChar())
  28.         randPasswordList[listInsert] = changeCase(randPasswordList[listInsert])
  29.         listInsert = listInsert + 1
  30.         continue
  31.     listInsert = 0
  32.     printList = 0
  33.     if lengthRandomGenerator <= 0:
  34.         print('It has to be longer than that')
  35. #    elif lengthRandomGenerator >= 25:
  36.         print('I can\'t generate a password that long')
  37.     elif math.isnan(lengthRandomGenerator):
  38.         print('error: not valid data type')
  39.     else:
  40.         while printList < (len(randPasswordList)-1):
  41.             printItem = randPasswordList[printList]
  42.             print(printItem)
  43.             printList = printList + 1
  44.     printList = 0
  45.     randPasswordList = []
  46. elif permissionRandomGenerator == 'no':
  47.     print('Too bad...')
  48. else:
  49.     print('You had to answer Yes or No')
Add Comment
Please, Sign In to add comment