简体   繁体   中英

PHP passing encrypted password by parameter

I pass encrypted password in the parameters of a function to connect to a database, but I don't know how to use it to connect to database?

function get_connectivity($pwd){    
    $host = "localhost";
    $user = "root";
    $pass = $pwd;
    $database = "testing";

    $db = new mysqli($host, $user, $pass, $database);
    if ($db->connect_errno) {
        return false;
        exit();
    }   
    $db->close();
    return true;
}

I call it this way:

get_connectivity(sha1("example"));

Is this even possible? Thanks.

Change to this. It is already declared, just pass it to the connection.

function get_connectivity($pwd){    
    $host = "localhost";
    $user = "root";
    $database = "testing";

    $db = new mysqli($host, $user, $pwd, $database);
    if ($db->connect_errno) {
        return false;
        exit();
    }   
    $db->close();
    return true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM