From de202ef1c3fd65e0ef43ebcf45fe48ae4b3516c8 Mon Sep 17 00:00:00 2001 From: Christian Ohlsson Date: Thu, 5 Feb 2026 13:30:20 +0100 Subject: [PATCH] Update version and author date in setPasswordforUser.sh Updated the script metadata and improved versioning. --- setPasswordforUser.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 setPasswordforUser.sh diff --git a/setPasswordforUser.sh b/setPasswordforUser.sh new file mode 100644 index 0000000..f80f5c6 --- /dev/null +++ b/setPasswordforUser.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# setPasswordforUser.sh +# +# Sätter ett lösenord på ett konto +# +# Christian Ohlsson 2025-09-21 +# Version 1.4 + +if [ "$#" -lt 1 -o "$#" -gt 2 ]; then + echo "Usage:`basename $0` username" + exit 1 +fi +username="$1" + +# Ask for password, twice +echo -n "Enter new password: "; +stty_orig=`stty -g` # save original terminal setting. +stty -echo # turn-off echoing. +read password1 # read the password + +echo -n "\nAnd again for confirmation: "; +read password2 # read the password +stty $stty_orig # restore terminal setting. +echo ""; # Force a newline + +# Check weather the password was enterred correctly +if [ "$password1" = "$password2" ]; then + echo "$username:$password1" | /usr/sbin/chpasswd + echo "ALTER USER '$username'@'localhost' IDENTIFIED BY '$password';" | mysql -u root + echo "FLUSH PRIVILEGES;" | mysql -u root + echo "Password changed for user: $username"; +else + echo "ERROR! Password mismatch. Enter your password twice."; +fi +exit 1