Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Secure class construction

Is it secure to call __construct() in login or sign up class this way:

function __construct(PDO $DBH, $_POST['1'], $_POST['2'])
{
    $this->_user=$_POST['1'];
    $this->_pass=$_POST['2'];
    $this->_DBH=$DBH;
}

I want to sanitize user input later inside this class and I'm not sure would my code be ripe for SQL injection or XSS because of class costructed with raw POST input?

like image 589
treng Avatar asked Aug 07 '26 21:08

treng


1 Answers

If you know you sanitize/use prepared statements (i.e. the raw POST data is not inserted as is to the query), it's fine to do so.

In fact, if you use prepared statements, you don't need to sanitize your input at all (for SQL, if you're going to display the data as HTML, it still needs to be sanitized as such).

like image 104
Madara's Ghost Avatar answered Aug 10 '26 11:08

Madara's Ghost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!