Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
Whole new experience of creating password.
  • Loading branch information
Hack Hunt committed May 15, 2021
1 parent 8ed9ec0 commit b72e8c5
Show file tree
Hide file tree
Showing 5 changed files with 273 additions and 52 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Password Generator
Generates Strong Random Password.
Generates Strong ( Random | Logical ) Password

### Supports Platform: Cross Platform

Expand All @@ -22,9 +22,15 @@
**Note:** On *macOS*, before running the file, you might need to run `chmod 755 generate_password` to make it *executable*.

### Available Arguments:
- **-h or --help:** *Displays all the available options.*
- **-c or --copy:** *Optional. Specifying this option will copy the generated password to clipboard.*
- **-l or --length:** *Optional. This option can be used to specify the length of the password. If this option is not used default length will be 12.*
- Program is divided into two parts:
- **strong:** *Generates strong random password.* **Usage:** `generate_password strong -h`
- **-l or --length:** *Optional. This option can be used to specify the length of the password.
If this option is not used default length will be 12.*
- **logical:** *Generates password on basis of questions you answered.* **Usage:** `generate_password logical -h`
- **-q or --ques-number:** *Optional. This option can be used to specify number of questions you want to answer.
Maximum is 4. If this options is not used default is random between 2 or 3.*
- **-h or --help:** *Displays all the available options.*
- **-c or --copy:** *Optional. Specifying this option will copy the generated password to clipboard.*

### Color Significance:
- **Green:** Successful.
Expand Down
Binary file modified executables/mac/generate_password
Binary file not shown.
Binary file modified executables/windows/generate_password.exe
Binary file not shown.
154 changes: 131 additions & 23 deletions generate_password.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#! /usr/bin/env python3

import argparse
from random import sample as select_random
import random
from pyperclip import copy
from termcolor import colored


def generate_password(pass_length):
def generate_strong_password(pass_length):

print(colored("\n[+] Generating Random Password...", 'blue'))

Expand All @@ -16,53 +16,161 @@ def generate_password(pass_length):
punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'

combination = list("{0}{1}{2}{3}".format(lower_alphabets, upper_alphabets, digits, punctuation))
password = select_random(combination, pass_length)
password = random.sample(combination, pass_length)
password = "".join(password)

return password


def generate_logical_password(ans_list):
print(colored("\n[+] Generating password with you answers...", "blue"))

password = ""
words = ["And", "Or", "With", "Go", "Is", "For", "The", "As", "If", "Nor", "But", "Yet"]

for _ in range(len(ans_list)):
y = random.randrange(len(ans_list))
x = random.randrange(len(words))
password = "{0}{1}".format(password, str(words[x]))
password = "{0}{1}".format(password, str(ans_list[y]))
ans_list.pop(y)
words.pop(x)

return password


def selector(length):
print(colored("[*] Select security questions numbers...\n", "blue"))

ques_lib = ["What is your mother's maiden name?",
"What is the name of your first car?",
"What elementary school did you attend?",
"Where was your best family vacation as a kid?",
"In which city does your nearest sibling lives?",
"What was your childhood name?",
"In which city did you meet your spouse/significant others?",
"In what city did your mother and father meet?",
"Where were you when you had your first kiss?",
"In which city or town was your first job?",
"What was your first pet?",
"What's your dream job?",
"What is your favourite movie of all times?",
"What is your favourite programming language?",
"At what age you lost your virginity?"]

for x in range(0, len(ques_lib)):
print("{0}: {1}".format(x + 1, ques_lib[x]))

ans_list = list()

while length > 0:

number = input(colored("\n[>] Enter the question number: \n>>> ", "yellow"))

if number.isdigit():
number = int(number) - 1
if not (0 <= number <= len(ques_lib) - 1):
print(colored("\n[-] Enter a valid question number.", "red"))
continue
else:
print(colored("\n[-] Enter a valid question number.", "red"))
continue

answer = input(colored("\n[>] {0}\n>>> ".format(ques_lib[number]), "yellow"))

if answer == "":
print(colored("\n[-] Enter a valid answer.", "yellow"))
continue

if answer.isalpha():
answer = answer.capitalize()
ans_list.append(answer)

length = length - 1

return ans_list


def get_arguments():
parser = argparse.ArgumentParser(prog="Password Generator",
usage="%(prog)s [options]\n\t[-l | --length] [number]",
formatter_class=argparse.RawDescriptionHelpFormatter,
description=""">>> | Password Generator v1.0 by Hack Hunt | <<<
description=""">>> | Password Generator v2.0 by Hack Hunt | <<<
----------------------------------------""")

parser._optionals.title = "Optional Argument"

parser.add_argument('-l', '--length',
dest='pass_length',
metavar='',
type=int,
default=12,
help='Specify the password length. Default is 12.')

parser.add_argument('-c', '--copy',
dest='copy',
action='store_true',
help='If specified, the password will be copied to clipboard.')
parser._optionals.title = "Optional Arguments"

parent_parser = argparse.ArgumentParser(add_help=False)

parent_parser.add_argument('-c', '--copy',
dest='copy',
action='store_true',
help='If specified, the password will be copied to clipboard.')

subparsers = parser.add_subparsers(title="Two possible options to choose from",
description="",
help="Type option -h/--help to know more about that command.",
metavar="strong/logical",
dest="cmd",
required=True)

parser_strong = subparsers.add_parser('strong',
description=">>> If specified, the program will generate strong password "
"using random characters.",
parents=[parent_parser],
help="strong -h/--help to know available options.")

parser_strong._optionals.title = "Available Arguments"

parser_logical = subparsers.add_parser('logical',
description=">>> If specified, few questions will be asked and will generate"
"password accordingly.",
parents=[parent_parser],
help="logical -h/--help to know available options.")

parser_logical._optionals.title = "Available Arguments"

parser_strong.add_argument('-l', '--length',
dest='pass_length',
metavar="<value>",
type=int,
default=12,
help='Specify the password length. Default is 12')

parser_logical.add_argument('-q', '--question-number',
dest="ques_number",
metavar='<value>',
type=int,
choices=range(1, 5),
default=random.randint(2, 3),
help="Specify number of questions you want to answer. Default is random.")

args = parser.parse_args()
return args


def main():
args = get_arguments()
pass_length = args.pass_length
copy_clipboard = args.copy

print(colored("[*] Initializing Password Generator v2.0 ...", "blue"))

if args.cmd == "logical":
ans_list = selector(args.ques_number)

try:
while True:
password = generate_password(pass_length)
if args.cmd == "strong":
password = generate_strong_password(args.pass_length)
else:
password = generate_logical_password(ans_list.copy())

print(colored("[+] Password generated successfully -> {0}".format(password), 'green'))

option = input(colored("\nAre you satisfied? [Y/N] (Default - Y)", 'yellow') + "\n>>> ").lower()
option = input(colored("\n[>] Are you satisfied? [Y/N] (Default - Y)\n>>> ", "yellow")).lower()

if option not in ['n', 'no']:
break

if copy_clipboard:
if args.copy:
copy(password)
print(colored("\n[+] Generated Password has been copied to clipboard", 'green'))
else:
Expand Down
Loading

0 comments on commit b72e8c5

Please sign in to comment.