Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,25 @@ Feel free to collaborate as you wish! 🙂
You will notice that the password is not actually printed out, this is a security preference, preventing it from being visible or saved anywhere easily accessible in the system.

# Guide

#There are 2 ways to use this tool

If you wish to generate a password anywhere and anytime with a single command follow these steps:
- After cloning the repo, cd into `bash-password-cp`.
- Run `chmod u+x run.sh`
- Run `sh ./run.sh <integer>` whereby the integer is a number between 6 and 30 (exclusive) specifying the length of the password
- Run `chmod u+x installer.sh`
- Run './installer.sh "<OS>" where OS is the operating system running on your machine. As of now, only MacOS and Windows are supported.
- Close the shell and open it again. You might get a message at the top, ignore it.
- Use the command `passgen <integer>` whereby the integer is a number between 6 and 30 (exclusive) specifying the length of the password
- Paste the password

You could also make it an alias in your command line. For example, if you're using `zsh`, you could run `alias -g [alias-name]="/path/to/project/run.sh"`. Then you type `[alias-name] 14`.
If you don't wish to turn it into a command and would rather just use the script everytime, follow these steps:
- After cloning the repo, cd into 'bash-password-cp'.
- run 'nano <OS>_version.sh' Where <OS> is "win" or "mac" for windows or mac respectively.
- write "passgen $1" at the very end of the file (after the '}')
- save and exit (ctrl S, ctrl X for windows. Cmd idk, cmd idk for mac)
- Run 'chmod u+x <os>_version.sh'
- Run './<os>_version.sh <integer>' where integer is a number between 6 and 30 (exclusive) specifying the length of the password
- Paste the password


That is all, thank you for downloading the tool and have a good day :)
20 changes: 20 additions & 0 deletions installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

function passgen() {
if [ $1 == 'Windows' ] || [ $1 == 'WINDOWS' ] || [ $1 == 'windows' ]
then
cp win_version.sh ~
echo "source ./win_version.sh" >> ~/.bashrc
echo "Installed the Windows version. Tell me you're basic without telling me you're basic."
elif [ $1 == 'MacOS' ] || [ $1 == 'macos' ] || [ $1 == 'MACOS' ] || [ $1 == 'MacOs' ] || [ $1 == 'macOs' ] || [ $1 == 'Macos' ]
then
cp mac_version.sh ~
echo "source ./mac_version.sh" >> ~/.bashrc
echo "Installed the mac version. Imagine using a mac. Ew. *cries without M1 chip*"
else
echo "You either wrote inalid input or a OS that we do not support. Either way sucks to be you."
fi
}


passgen $1 2> /dev/null
61 changes: 61 additions & 0 deletions mac_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
#############
# File name: run.sh
# Purpose: When executed, this will copy a complex password to the user's clipboard
# Created by: Christophe El-Khoury (thelebdev)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the Created by part of the documentation and the file name

# Created at: 24-02-2021, Byblos - Lebanon
###########

passgen(){

# Array holding all of the characters used in the password
DICTIONARY=(a b c d e f g h i j k l m n o p q r s t u v w x y n z A B C D E F G H I J K L M N O P Q R S T U V W X Y N Z ! \" \# \$ \% \& \' \( \) \* \+ \, \- \. \/ \: \; \< \= \> \? \@ \[ \\ \] \^ \_ \` \{ \| \} \~ )

# User's input, the password's length
PASSWORD_LENGTH=$1

###
# This function will validate a user's confirmation choice
###
function VALIDATE_CONFIRMATION {
read CONFIRMATION
echo $CONFIRMATION
if [[ $CONFIRMATION != "y" ]] && [[ $CONFIRMATION != "Y" ]]
then
echo "Aborting..."
exit 1
fi
}

if [ -z $PASSWORD_LENGTH ]
then
PASSWORD_LENGTH=14
echo "Generating password of length ${PASSWORD_LENGTH} (default)"
else
echo "Generating password of length ${PASSWORD_LENGTH} (custom)"
fi


if [ $PASSWORD_LENGTH -lt 6 ]
then
echo "You are generating a weak password ($PASSWORD_LENGTH characters). Are you sure you want to continue? (y/n)"
VALIDATE_CONFIRMATION
fi

if [ $PASSWORD_LENGTH -gt 30 ]
then
echo "You are generating a very long password ($PASSWORD_LENGTH characters). Are you sure you want to continue? (y/n)"
VALIDATE_CONFIRMATION
fi


PASSWORD=""

for (( c=0; c<$PASSWORD_LENGTH; c++ ))
do
PASSWORD=$PASSWORD${DICTIONARY[$RANDOM % ${#DICTIONARY[@]}]}
done
echo "Password copied in your clipboard"
echo $PASSWORD | pbcopy

}
57 changes: 0 additions & 57 deletions run.sh

This file was deleted.

62 changes: 62 additions & 0 deletions win_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
#############
# File name: run.sh
# Purpose: When executed, this will copy a complex password to the user's clipboard
# Created by: Christophe El-Khoury (thelebdev)
# Created at: 24-02-2021, Byblos - Lebanon
###########

passgen(){

# Array holding all of the characters used in the password
DICTIONARY=(a b c d e f g h i j k l m n o p q r s t u v w x y n z A B C D E F G H I J K L M N O P Q R S T U V W X Y N Z ! \" \# \$ \% \& \' \( \) \* \+ \, \- \. \/ \: \; \< \= \> \? \@ \[ \\ \] \^ \_ \` \{ \| \} \~ )

# User's input, the password's length
PASSWORD_LENGTH=$1

###
# This function will validate a user's confirmation choice
###
function VALIDATE_CONFIRMATION {
read CONFIRMATION
echo $CONFIRMATION
if [[ $CONFIRMATION != "y" ]] && [[ $CONFIRMATION != "Y" ]]
then
echo "Aborting..."
exit 1
fi
}

if [ -z $PASSWORD_LENGTH ]
then
PASSWORD_LENGTH=14
echo "Generating password of length ${PASSWORD_LENGTH} (default)"
else
echo "Generating password of length ${PASSWORD_LENGTH} (custom)"
fi


if [ $PASSWORD_LENGTH -lt 6 ]
then
echo "You are generating a weak password ($PASSWORD_LENGTH characters). Are you sure you want to continue? (y/n)"
VALIDATE_CONFIRMATION
fi

if [ $PASSWORD_LENGTH -gt 30 ]
then
echo "You are generating a very long password ($PASSWORD_LENGTH characters). Are you sure you want to continue? (y/n)"
VALIDATE_CONFIRMATION
fi


PASSWORD=""

for (( c=0; c<$PASSWORD_LENGTH; c++ ))
do
PASSWORD=$PASSWORD${DICTIONARY[$RANDOM % ${#DICTIONARY[@]}]}
done
echo "Password copied in your clipboard"
echo $PASSWORD | clip

}