Skip to content

Instantly share code, notes, and snippets.

@shirkey
Last active August 29, 2015 13:56
Show Gist options
  • Save shirkey/9208345 to your computer and use it in GitHub Desktop.
Save shirkey/9208345 to your computer and use it in GitHub Desktop.
dovecot-password_generator_shell_functions
function password () {
echo "$(< /dev/urandom tr -dc "A-Za-z0-9" | head -c${1:-16};echo;)"
}
function dovecot-hash(){
if [ -z "${1}" ]
then
echo "requires password to be hashed -- exiting"
return 1
else
echo $(doveadm pw -p ${1} -s sha512 -r 100)
fi
}
function dovecot-create-user(){
if [ -z "${1}" ]
then
echo "this command requires an argument of the userid to be created -- exiting"
return 1
else
local user="${1}"
local fquser="${1}@$HOSTNAME"
echo "Creating user ${fquser}"
fi
local p=$(password)
local hash=$(dovecot-hash ${p})
echo "Created user ${fquser} with password ${p}..."
psql -U mailreader -d mail -c "INSERT INTO users (email, password, maildir) VALUES ('${fquser}','${hash}','${user}/');"
echo "Confirming user ${fquser} exists..."
psql -U mailreader -d mail -c "SELECT * FROM users WHERE email='${fquser}'"
echo "Finished"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment