Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
Create a strong password using random characters
  • Loading branch information
abhi-agrawl committed Apr 17, 2021
1 parent b200ba0 commit 8ed9ec0
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 2 deletions.
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
# password-generator
Generates Strong Random Password.
# Password Generator
Generates Strong Random Password.

### Supports Platform: Cross Platform

### Programming Language: Python 3 and above

### How to use:
1. If you have *Python3* installed. You can use the `.py` file. Make sure to install `pyperclip` package - `python -m pip install pyperclip`.
- For *Windows*, use [generate_password_no_color.py][1] file.
- For *Linux/macOS*, you can use any `.py` file. But if you are using colored version i.e., [generate_password.py][2] make sure you install, *termcolor* package (`python -m pip install termcolor`) in Python.
- For *Linux*, you need to install `xclip` using command - `sudo apt install xclip`

2. You can use **binaries/executable** version as well.
- Binaries are in [executables][6] folder.
- For ***Windows*** -> [Download][3]
- For ***macOS*** -> [Download][5]
- After downloading, paste the file in `Documents` folder and open **Terminal/Command Prompt**.
- Enter the command, `cd Documents`.
- Run the file by typing `./` followed by file name. For eg., `./generate_password.exe` (for Windows) and `./generate_password` (for macOS).

**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.*

### Color Significance:
- **Green:** Successful.
- **Blue:** In process.
- **Red:** Unsuccessful or Errors.
- **Yellow:** User Input.

### Licensed: GNU General Public License, version 3

### Developer Information:
- **Website:** https://www.hackhunt.in/
- **Contact:** [email protected]
- **LinkedIn:** https://www.linkedin.com/company/hackhunt
- **Youtube:** [@hackhunt](https://youtube.com/hackhunt)
- **Instagram:** [@hh.hackhunt](https://www.instagram.com/hh.hackhunt/)
- **Facebook:** [@hh.hackhunt](https://www.facebook.com/hh.hackhunt/)
- **Twitter:** [hh_hackhunt](https://twitter.com/hh_hackhunt/)
- **Patreon:** [@hackhunt](https://www.patreon.com/hackhunt)

[1]: ./generate_password_no_color.py
[2]: ./generate_password.py
[3]: ./executables/windows/
[5]: ./executables/mac/
[6]: ./executables/
Binary file added executables/mac/generate_password
Binary file not shown.
Binary file added executables/windows/generate_password.exe
Binary file not shown.
80 changes: 80 additions & 0 deletions generate_password.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#! /usr/bin/env python3

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


def generate_password(pass_length):

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

lower_alphabets = "qwertyuiopasdfghjklmnbvcxz"
upper_alphabets = lower_alphabets.upper()
digits = '0123456789'
punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'

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

return password


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 | <<<
----------------------------------------""")

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.')

args = parser.parse_args()
return args


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

try:
while True:
password = generate_password(pass_length)
print(colored("[+] Password generated successfully -> {0}".format(password), 'green'))

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

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

if copy_clipboard:
copy(password)
print(colored("\n[+] Generated Password has been copied to clipboard", 'green'))
else:
print(colored("\n[!] Password is not copied to clipboard, make sure to copy it.", 'red'))

except KeyboardInterrupt:
print(colored("\n[+] User interrupted. Exiting...", 'red'))

except BaseException as e:
print(colored("\n[-] Error: {0}".format(e), 'red'))


#####################################################
if __name__ == '__main__':
main()
79 changes: 79 additions & 0 deletions generate_password_no_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#! /usr/bin/env python3

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


def generate_password(pass_length):

print("\n[+] Generating Random Password...")

lower_alphabets = "qwertyuiopasdfghjklmnbvcxz"
upper_alphabets = lower_alphabets.upper()
digits = '0123456789'
punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'

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

return password


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 | <<<
----------------------------------------""")

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.')

args = parser.parse_args()
return args


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

try:
while True:
password = generate_password(pass_length)
print("[+] Password generated successfully -> {0}".format(password))

option = input("\nAre you satisfied? [Y/N] (Default - Y)\n>>> ").lower()

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

if copy_clipboard:
copy(password)
print("\n[+] Generated Password has been copied to clipboard")
else:
print("\n[!] Password is not copied to clipboard, make sure to copy it.")

except KeyboardInterrupt:
print("\n[+] User interrupted. Exiting...")

except BaseException as e:
print("\n[-] Error: {0}".format(e))


#####################################################
if __name__ == '__main__':
main()

0 comments on commit 8ed9ec0

Please sign in to comment.