-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewPy.py
executable file
·67 lines (53 loc) · 1.83 KB
/
newPy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
import random
import string
class Password:
OPTIONS = {'#': string.digits, 'a': string.lowercase,
'A': string.uppercase, 's': string.punctuation}
def __init__(self, userInput):
self.length = 0
self.options = []
self.password = ''
self.sequence = ''
self.checkOptions(userInput)
self.createSequence()
def checkOptions(self, userInput):
for letter in set(userInput):
if letter in Password.OPTIONS:
self.options.append(letter)
numFilter = lambda x: x in string.digits
num = filter(numFilter, userInput)
if num and 0 < int(num) <= 50:
self.length = int(num)
else:
self.enterLength()
def enterLength(self):
print 'Enter in a length greater than zero but less than 50.'
num = raw_input()
try:
num = int(num)
if 0 < num <= 50:
self.length = num
else:
self.enterLength()
except ValueError:
self.enterLength()
def createSequence(self):
for option in self.options:
self.sequence += Password.OPTIONS[option]
def createPassword(self):
if self.sequence:
for i in range(self.length):
self.password += random.choice(self.sequence)
return self.password
if __name__ == "__main__":
print "Welcome to Password Generator V 2.0"
print "\nHere are options for creating your password:"
print "\tEnter, seperated by a space, your selections:"
print "\n\tA numerical value for length"
print "\t's' for symbols"
print "\t'A' for capital letters"
print "\t'a' for lowercase letters"
print "\t'#' for numbers"
myPassword = Password(raw_input())
print myPassword.createPassword()