#!/bin/bash
PASSFILE="/usr/local/open***/conf/passwd"
LOG_FILE="/usr/local/open***/logs/open***-password.log"
TIME_STAMP=`date "+%Y-%m-%d %T"`
###########################################################
if [ ! -r "${PASSFILE}" ]; then
echo "${TIME_STAMP}: Could not open password file "${PASSFILE}" for reading." >> ${LOG_FILE}
exit 1
fi
CORRECT_PASSWORD=`awk '!/^;/&&!/^#/&&$1=="'${username}'"{print $2;exit}' ${PASSFILE}`
if [ "${CORRECT_PASSWORD}" = "" ]; then
echo "${TIME_STAMP}: User does not exist: username="${username}", password="${password}"." >> ${LOG_FILE}
exit 1
fi
if [ "${password}" = "${CORRECT_PASSWORD}" ]; then
echo "${TIME_STAMP}: Successful authentication: username="${username}"." >> ${LOG_FILE}
exit 0
fi
echo "${TIME_STAMP}: Incorrect password: username="${username}", password="${password}"." >> ${LOG_FILE}
exit 1
#!/bin/bash
HOST="localhost"
DB="open***"
DBUSER="open***"
DBPASS="123456"
DBTABLE='open***_user'
user=`echo ${username}|sed "s#'\|;\|=\|%##g"`
MYSQL="/usr/bin/mysql -h${HOST} -u${DBUSER} -p${DBPASS} "
result=`$MYSQL << EOF |tail -n +2
select count(1) from ${DB}.${DBTABLE} WHERE is_enabled='1' AND is_***='1' AND password=md5('${password}') AND username='${user}';
EOF`
if [ $result -eq 1 ];then
exit 0;
else
exit 1;
fi
数据库的表结构就是
create database open***;
use open***;
create table open***_user (id int(11) not null primary key auto_increment,username varchar(64) not null,password char(64) not null,is_*** tinyint(1) default 1,is_enabled tinyint(1) default 1);
grant all on open***.* to 'open***'@'localhost' identified by '123456';
flush privileges;