Look at the -p options to useradd and usermod.
Sample code snip:
Code:
#!/bin/bash
##
## Set a default password and perform a password reset
l_user=$1
if [ "$l_user" != "" ]
then
l_password="Reset"
l_encrypted_pass=$(mkpasswd -s --hash=md5 ${l_password})
echo "/usr/sbin/usermod -p ${l_encrypted_pass} ${l_user}"
## Uncomment when you are happy with the test results
##/usr/sbin/usermod -p ${l_encrypted_pass} ${l_user}
fi
EDIT:-
As this script would need to run as root, you need to perform enough checking so that you are happy that users will not be able to break your system (intentionally or otherwise)
Do you want to allow root (and other system accounts) to have their passwords reset? I would suggest not, so you might need to check the contents against a blocked list.
Also I would suggest checking that ;'&> (and possibly other) characters are not contained in $user
I would test by passing incorrect data to see what it echos:
./script 'user;cat /etc/shadow'
./script root
./script >/tmp/etc/passwd -- Don't test directly with /etc/passwd or other files that are key to the system
This is probably not a definitive list of ways to use this script to break a system, but it's what I can think of at the moment.