Python file and bash script

This commit is contained in:
Maximilian P. Käfer 2022-03-25 17:03:28 +01:00
parent 5cc39f6f82
commit 435e01442a
Signed by: mpk
GPG Key ID: 035869C949377C5C
2 changed files with 82 additions and 0 deletions

54
pwgen.sh Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env bash
imp="import pwgenerator as g;"
function _help() {
echo "Usage: pwgen [length] [mode]"
echo ""
echo "Available modes:"
printf " %-15s\t%s\n" \
"numbers" "Generates password containing only numbers" \
"lower" "Generates password containing only lower letters" \
"upper" "Generates password containing only upper letters" \
"letters" "Generates password containing only letters" \
"letters-numbers" "Generates password containing only letters and ners" \
"full" "Generates password containing letters, numbers and symbols" \
}
case "$#" in
0)
_help
;;
1)
python -c "${imp} g.genFull($1)"
;;
2)
case "$2" in
numbers)
python -c "${imp} g.genNum($1)"
;;
lower)
python -c "${imp} g.genLetLow($1)"
;;
upper)
python -c "${imp} g.genLetUp($1)"
;;
letters)
python -c "${imp} g.genLet($1)"
;;
letters-numbers)
python -c "${imp} g.genLetNum($1)"
;;
full)
python -c "${imp} g.genFull($1)"
;;
*)
_help
;;
esac
;;
*)
_help
;;
esac

28
pwgenerator.py Normal file
View File

@ -0,0 +1,28 @@
import random
lower = "abcdefghijklmnopqrstuvwxyz"
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numbers = "0123456789"
symbols = "!$%&/?+*-#"
def genNum(length):
gen(numbers, length)
def genLetLow(length):
gen(lower, length)
def genLetUp(length):
gen(upper, length)
def genLet(length):
gen(lower + upper, length)
def genLetNum(length):
gen(lower + upper + numbers, length)
def genFull(length):
gen(lower + upper + numbers + symbols, length)
def gen(chars, length):
print(''.join(random.choice(chars) for _ in range(length)))