Passwortgenerator

Aus wiki.archlinux.de
Version vom 4. November 2012, 18:42 Uhr von SiD (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „Ein einfacher Passwortgenerator #!/bin/bash # Generate a random password # # $1 number of characters; defaults to 20 # # $2 charset # 0 = special ch…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

Ein einfacher Passwortgenerator

#!/bin/bash

# Generate a random password
#
# $1 number of characters; defaults to 20
#
# $2 charset 
# 0 = special characters, numbers and letters (default)
# 1 = numbers and letters
# 2 = letters only
#
#
# usage: pwgen.sh <LENGTH> <CHARS>
#
# examples: 
#
# length = 20, special characters, numbers and letters
# pwgen.sh 
#
# length = 10, special characters, numbers and letters
# pwgen.sh 10
#
# length = 8, numbers and letters
# pwgen.sh 8 1
#
# length = 25, letters only
# pwgen.sh 25 2


	
if [ "$1" = "" ]; then
	LENGTH=20;
else
	LENGTH=$1
fi


if [ "$2" = "" ]; then
	CHARS="[:graph:]"
fi

if [ "$2" = "1" ]; then
	CHARS="[:alnum:]"
fi

if [ "$2" = "2" ]; then
	CHARS="[:alpha:]"
fi


cat /dev/urandom | tr -dc $CHARS | head -c $LENGTH
echo