Add token/password generation function

This commit is contained in:
Rémi Bédard-Couture 2024-03-08 23:05:00 -05:00
parent bec069c732
commit 3f5716291b
1 changed files with 14 additions and 0 deletions

View File

@ -197,3 +197,17 @@ EOF
echo "bash -c \"\$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/ct/${app}.sh)\"" >/usr/bin/update
chmod +x /usr/bin/update
}
# This function generates a token. The length of the token needs to be passed as the first parameter, otherwise defaults to 30
generate_token() {
token_len=30
#check if first parameter was passed and it's an integer
if [ $# -ge 1 ] && [ ! -z "$1" ] && [[ $1 =~ ^[-+]?[0-9]+$ ]]; then
token_len=$1
fi
#For some reason, the /dev/urandom approach does not work inside an install script
#tr -dc A-Za-z0-9 </dev/urandom | head -c$token_len
openssl rand -base64 $token_len
}