From cc1e5c98239cb4bd83e6fbdbbba5651f163811a5 Mon Sep 17 00:00:00 2001 From: Moahamad Riad Terek Date: Mon, 11 Jul 2022 14:52:43 +0300 Subject: [PATCH] Riad's commit --- README.md | 22 +++++++++++++++--- installer.sh | 20 ++++++++++++++++ mac_version.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ run.sh | 57 ---------------------------------------------- win_version.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+), 60 deletions(-) create mode 100644 installer.sh create mode 100644 mac_version.sh delete mode 100755 run.sh create mode 100644 win_version.sh diff --git a/README.md b/README.md index 7501d38..bfe22a4 100644 --- a/README.md +++ b/README.md @@ -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 ` 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 "" 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 ` 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 _version.sh' Where 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 _version.sh' +- Run './_version.sh ' 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 :) diff --git a/installer.sh b/installer.sh new file mode 100644 index 0000000..382c8ad --- /dev/null +++ b/installer.sh @@ -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 diff --git a/mac_version.sh b/mac_version.sh new file mode 100644 index 0000000..c36aeeb --- /dev/null +++ b/mac_version.sh @@ -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) +# 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 + +} diff --git a/run.sh b/run.sh deleted file mode 100755 index 5200208..0000000 --- a/run.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/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 -########### - -# 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 diff --git a/win_version.sh b/win_version.sh new file mode 100644 index 0000000..0d85065 --- /dev/null +++ b/win_version.sh @@ -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 + +} +