如何使用PHP加密密码? - MySQL

时间:2016-09-21 22:51:24

标签: php mysql encryption

我可以使用此查询创建数据库

$dbh->exec("CREATE DATABASE `$db` CHARACTER SET utf8 COLLATE utf8_bin;
             CREATE USER '$user'@'%' IDENTIFIED BY '$pass';
             GRANT USAGE ON *.* TO '$db'@'localhost' IDENTIFIED BY PASSWORD '*3D3B92F242033365AE5BC6A8E6FC3E1679F4140A';
             GRANT ALL PRIVILEGES ON `$username\_$dbusername`.* TO '$user'@'localhost';") 

但加密密码包含在查询中:

'*3D3B92F242033365AE5BC6A8E6FC3E1679F4140A'

解密版本:

test1234

这是由MySQL自动加密的,如何用PHP加密test1234

完整版

$user='abc_dbuser';
$db="abc_dbname";
$pass='test1234';
$dbusername="dbname";
$username=get_current_user();

    try {
        $dbh = new PDO("mysql:host=$host", $root, $root_password);
        $dbh->exec("CREATE DATABASE `$db` CHARACTER SET utf8 COLLATE utf8_bin;
                    CREATE USER '$user'@'%' IDENTIFIED BY '$pass';

                    GRANT USAGE ON *.* TO '$db'@'localhost' IDENTIFIED BY PASSWORD '*3D3B92F242033365AE5BC6A8E6FC3E1679F4140A';
                    GRANT ALL PRIVILEGES ON `$username\_$dbusername`.* TO '$user'@'localhost';
                    ") 
        or die(print_r($dbh->errorInfo(), true));

my other question

0 个答案:

没有答案