2013-01-21 17:16:46 +00:00
|
|
|
#!/bin/bash
|
2009-09-08 05:29:38 +00:00
|
|
|
|
|
|
|
# First check that we have a username as $1. If not, ask for the username
|
|
|
|
if [ "$#" -eq 0 ]
|
|
|
|
then
|
|
|
|
echo -n "Please enter the login : "
|
|
|
|
read LOGIN
|
|
|
|
else
|
|
|
|
LOGIN="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that the login exists :
|
|
|
|
MYSQL="mysql --defaults-file=/etc/alternc/my.cnf --skip-column-name alternc -B -e "
|
|
|
|
|
|
|
|
USERID="`$MYSQL "SELECT uid FROM membres WHERE login='${LOGIN}'"`"
|
|
|
|
|
|
|
|
if [ ! "$USERID" ]
|
|
|
|
then
|
|
|
|
echo "Login '$LOGIN' not found"
|
|
|
|
if [ "$LOGIN" = "admin" ]
|
|
|
|
then
|
|
|
|
echo "You may try 'root' instead (old alternc)"
|
|
|
|
fi
|
|
|
|
if [ "$LOGIN" = "root" ]
|
|
|
|
then
|
|
|
|
echo "You may try 'admin' instead (new alternc)"
|
|
|
|
fi
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
echo -n "Please enter the new password : "
|
2013-01-21 17:16:46 +00:00
|
|
|
read -s PASS
|
2009-09-08 05:29:38 +00:00
|
|
|
echo
|
|
|
|
echo -n "Please confirm the new password : "
|
2013-01-21 17:16:46 +00:00
|
|
|
read -s PASS2
|
2009-09-08 05:29:38 +00:00
|
|
|
echo
|
|
|
|
if [ "$PASS" != "$PASS2" ]
|
|
|
|
then
|
|
|
|
echo "Passwords are differents, aborting"
|
|
|
|
exit -2
|
|
|
|
fi
|
|
|
|
|
|
|
|
RND="`echo -n $RANDOM $RANDOM $RANDOM`"
|
|
|
|
$MYSQL "UPDATE membres SET pass=ENCRYPT('$PASS',CONCAT('\$1\$',MD5('$RND'))) WHERE uid='$USERID'"
|
|
|
|
if [ "$?" ]
|
|
|
|
then
|
|
|
|
echo "Password changed successfully"
|
|
|
|
fi
|