31 lines
400 B
Bash
Executable File
31 lines
400 B
Bash
Executable File
#!/bin/bash
|
|
|
|
function usage {
|
|
echo "./htpasswd.sh <username> <file>"
|
|
}
|
|
|
|
if [ $1 ]; then
|
|
USER=$1
|
|
else
|
|
USER=$(whoami)
|
|
fi
|
|
|
|
SUCCESS=1
|
|
while [ $SUCCESS -ne 0 ]; do
|
|
PASSWD=$(openssl passwd -apr1)
|
|
if [ $? -eq 0 ]; then
|
|
SUCCESS=0
|
|
fi
|
|
done
|
|
|
|
if [ $2 ]; then
|
|
FILE=$2
|
|
if [ $FILE ]; then
|
|
echo "$USER:$PASSWD" >> $FILE
|
|
fi
|
|
else
|
|
echo "$USER:$PASSWD"
|
|
fi
|
|
|
|
exit 0
|