Skip to content

Commit a688770

Browse files
committed
Password Generator Script Added
1 parent 3ec7811 commit a688770

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

Password Generator/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Password Generator Script
2+
The python script can generate a password using ASCII, Digits and Special Characters of desired length.
3+
4+
What the program does?
5+
- Default generates password with ASCII, Digits and Special Characters
6+
- Can mix match (between ASCII, Digits and Special Characters) and generate a password
7+
8+
9+
10+
### Requirements
11+
Python3.6+
12+
13+
14+
### Usage
15+
```
16+
password.py [-h] -l [LENGTH] [-a] [-d] [-p]
17+
18+
GENERATE RANDOM PASSWORD OF LENGTH SPECIFIED WITH MIX AND MATCH. DEFAULT HAS
19+
ASCII,DIGITS AND PUNCTUATIONS INCLUDED WITH LENGTH OF EIGHT
20+
21+
optional arguments:
22+
-h, --help show this help message and exit
23+
-l [LENGTH] Length For Password
24+
-a Use ASCII Characters
25+
-d Use Digits
26+
-p Use Special Characters
27+
28+
```
29+
30+
### Contribution
31+
32+
Any kind of contributions are welcome.
33+
34+
1. Fork the Project
35+
2. Commit your Changes
36+
3. Open a Pull Request
37+
38+

Password Generator/password.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import argparse
2+
import random
3+
import string
4+
5+
6+
def PasswordGenerator(combine, length):
7+
""" Generates a random password having the specified length. Default length 8 is passed """
8+
9+
# Sends the combined string to choice method
10+
password = ''.join(random.choice(combine) for x in range(length))
11+
12+
print(f"String Of Length {length} is: {password}")
13+
14+
15+
def main():
16+
parser = argparse.ArgumentParser(
17+
description='GENERATE RANDOM PASSWORD OF LENGTH SPECIFIED WITH MIX AND MATCH. DEFAULT HAS ASCII,DIGITS AND '
18+
'PUNCTUATIONS INCLUDED WITH LENGTH OF EIGHT')
19+
20+
# Argument is for a length of the password
21+
parser.add_argument('-l', dest='length', type=int, nargs='?', const=8, help='Length For Password', required=True)
22+
23+
# Argument is for ascii characters
24+
parser.add_argument('-a', dest='ascii', action='store_true', help='Use ASCII Characters')
25+
26+
# Argument is for digits
27+
parser.add_argument('-d', dest='digit', action='store_true', help='Use Digits')
28+
29+
# Argument is for punctuations
30+
parser.add_argument('-p', dest='punctuation', action='store_true', help='Use Special Characters')
31+
32+
args = parser.parse_args()
33+
34+
# Checks if the number is a positive integer
35+
if args.length > 0:
36+
lenPass = args.length
37+
38+
# create alphanumerical from string constants
39+
combine = [string.ascii_letters, string.digits, string.punctuation]
40+
41+
# Generate string using ascii,digit and punctuation
42+
if args.ascii and args.digit and args.punctuation:
43+
# Call the function
44+
PasswordGenerator(str(combine[0] + combine[1] + combine[2]), lenPass)
45+
46+
# Generate string using ascii and digits
47+
elif args.ascii and args.digit:
48+
# Call the function
49+
PasswordGenerator(str(combine[0] + combine[1]), lenPass)
50+
51+
# Generate string using ascii and punctuation
52+
elif args.ascii and args.punctuation:
53+
# Call the function
54+
PasswordGenerator(str(combine[0] + combine[2]), lenPass)
55+
56+
# Generate string using digit and punctuation
57+
elif args.digit and args.punctuation:
58+
# Call the function
59+
PasswordGenerator(str(combine[1] + combine[2]), lenPass)
60+
61+
# Generate string using ascii
62+
elif args.ascii:
63+
# Call the function
64+
PasswordGenerator(str(combine[0]), lenPass)
65+
66+
# Generate string using digit
67+
elif args.digit:
68+
# Call the function
69+
PasswordGenerator(str(combine[1]), lenPass)
70+
71+
# Generate string using punctuation
72+
elif args.punctuation:
73+
# Call the function
74+
PasswordGenerator(str(combine[2]), lenPass)
75+
76+
else:
77+
# Call the function
78+
PasswordGenerator(str(combine[0] + combine[1] + combine[2]), lenPass)
79+
80+
else:
81+
print("Enter A Positive Integer")
82+
83+
84+
if __name__ == '__main__':
85+
main()

0 commit comments

Comments
 (0)