pdo bindParam case sensitive

2019-08-29 11:04发布

问题:

I want to check if the password is correct (Case sensitive). Currently, I'm using PDO, something like this:

$sql = 'select * from User
        WHERE Email = :user and Password = :pass AND idRole = :role AND idState_User = :state';

    $stat = $this->_db->prepare($sql);
    $stat->bindParam(':user', $user, PDO::PARAM_STR);    
    $stat->bindParam(':pass', $password, PDO::PARAM_STR);  
    $stat->bindParam(':state', $idState_User, PDO::PARAM_INT);  
    $stat->bindParam(':role', $idRole, PDO::PARAM_INT);          
    $stat->execute();

I would like :pass to be case sensitive because if the password is "paSs1234", I can logged in with PASS1234, pass1234 or paSs1234. How can I do to make this case sensitive? Thanks in advance.

回答1:

$sql = 'select * from User
        WHERE Email = :user 
          AND BINARY `Password` = :pass 
          AND idRole = :role
          AND idState_User = :state';