* adjust for encrypt password.

This commit is contained in:
wangyidong
2020-12-07 18:08:35 +08:00
parent 5d394844d6
commit badeb97dca
4 changed files with 77 additions and 1 deletions

View File

@@ -164,6 +164,13 @@ if %requestType% == 'PATH_INFO' (
echo %deletelog% > %baseDir%deletelog.bat
echo deletelog.bat ok
:: encrypt.
if exist "%baseDir%php\encrypt.php" (
SET encrypt= %phpcli% %baseDir%php\encrypt.php %%*
echo %encrypt% > %baseDir%encrypt.bat
echo encrypt.bat ok
)
:: create crond.bat
SET cron= %phpcli% %baseDir%php\crond.php
echo %cron% > %baseDir%crond.bat

View File

@@ -167,6 +167,13 @@ fi
echo $deletelog > $basePath/deletelog.sh
echo "deletelog.sh ok"
# encrypt.
if [ -f "$basePath/php/encrypt.php" ]; then
encrypt="$phpcli $basePath/php/encrypt.php \$*"
echo $encrypt > $basePath/encrypt.sh
echo "encrypt.sh ok"
fi
# cron
if [ ! -d "$basePath/cron" ]; then
mkdir $basePath/cron

View File

@@ -267,6 +267,66 @@ class baseHelper
return (function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()) ? addslashes(json_encode($data)) : json_encode($data);
}
/**
* Encrypt password
*
* @param string $password
* @static
* @access public
* @return string
*/
public static function encryptPassword($password)
{
global $config;
$encrypted = '';
if(!empty($config->encryptSecret) and $password)
{
$secret = $config->encryptSecret;
if(function_exists('mcrypt_encrypt'))
{
$encrypted = base64_encode(@mcrypt_encrypt(MCRYPT_DES, $secret, $password, MCRYPT_MODE_CBC));
}
elseif(function_exists('openssl_encrypt'))
{
$encrypted = @openssl_encrypt($password, 'des-cbc', $secret);
}
}
if(empty($encrypted)) $encrypted = $password;
return $encrypted;
}
/**
* Decrypt password.
*
* @param string $password
* @static
* @access public
* @return string
*/
public static function decryptPassword($password)
{
global $config;
$decryptedPassword = '';
if(!empty($config->encryptSecret) and $password)
{
$secret = $config->encryptSecret;
if(function_exists('mcrypt_decrypt'))
{
$decryptedPassword = mcrypt_decrypt(MCRYPT_DES, $secret, base64_decode($password), MCRYPT_MODE_CBC);
}
elseif(function_exists('openssl_decrypt'))
{
$decryptedPassword = openssl_decrypt($password, 'des-cbc', $secret);
}
}
if(empty($decryptedPassword)) $decryptedPassword = $password;
return $decryptedPassword;
}
/**
* 判断是否是utf8编码
* Judge a string is utf-8 or not.

View File

@@ -2147,7 +2147,9 @@ class baseRouter
}
try
{
$dbh = new PDO($dsn, $params->user, $params->password, array(PDO::ATTR_PERSISTENT => $params->persistant));
$dbPassword = helper::decryptPassword($params->password);
$dbh = new PDO($dsn, $params->user, $dbPassword, array(PDO::ATTR_PERSISTENT => $params->persistant));
$dbh->exec("SET NAMES {$params->encoding}");
/*