-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordGenerator.py
78 lines (72 loc) · 2.7 KB
/
PasswordGenerator.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
68
69
70
71
72
73
74
75
76
77
78
################################################################
## This script creates passwords based on user requirements ##
## 1) Length ##
## 2) Number of passwords to be generated ##
## 3) Password must have Upper Case ##
## 4) Password must have Lower Case ##
## 5) Password must have Special Character ##
## 6) Password must have Number ##
## ##
## ##
## Copyright(c) 2021 Wardell Castles vvvvvv ##
## http://red7en.com ##
################################################################
import string
import random
allLetters = string.ascii_letters
upperLetters = string.ascii_uppercase
lowerLetters = string.ascii_lowercase
numberLetters = string.digits
specialLetters = string.punctuation
pwdLength = input("Password length ")
if int(pwdLength) < 4:
print("Password Length must be greater than 4")
exit()
nbrPasswords = input("Number of passwords to be generated ")
mustContainUpper = input("Must contain UPPER CASE (Y/n")
mustContainLower = input("Must contain lower case (Y/n")
mustContainSpecial = input("Must contain Special Character (Y/n")
mustContainNumber = input("Must contain a Number (Y/n")
mustHaveUpper = False
mustHaveLower = False
mustHaveSpecial = False
mustHaveNumber = False
if(mustContainNumber == "Y"):
mustHaveNumber = True
if(mustContainSpecial == "Y"):
mustHaveSpecial = True
if(mustContainUpper == "Y"):
mustHaveUpper = True
if(mustContainLower == "Y"):
mustHaveLower = True
haveUppper = False
haveLower = False
haveSpecial = False
haveNumber = False
pwdCounter = 1
while pwdCounter <= int(nbrPasswords):
passWord=''
while len(passWord) < int(pwdLength):
aLetter=random.choice(allLetters)
#Test for Number
isNumber = aLetter.find(string.digits)
if isNumber != -1 and mustHaveNumber:
havenumber = True
passWord += aLetter
#Test for Special
isSpecial = aLetter.find(string.punctuation)
if isSpecial != -1 and mustHaveSpecial:
haveSpecial = True
passWord += aLetter
#Test for Upper
isUpper = aLetter.isupper()
if isUpper and mustHaveUpper:
haveUpper = True
passWord += aLetter
#Test for lower
isLower = aLetter.islower()
if isLower and mustHaveLower:
haveLower = True
passWord += aLetter
print(passWord)
pwdCounter += 1