Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing bad data input

Is it good practice to delegate data validation entirely to the database engine constraints?

Validating data from the application doesn't prevent invalid insertion from another software (possibly written in another language by another team). Using database constraints you reduce the points where you need to worry about invalid input data.

If you put validation both in database and application, maintenance becomes boring, because you have to update code for who knows how many applications, increasing the probability of human errors.

I just don't see this being done very much, looking at code from free software projects.

like image 202
Eduardo Marinho Avatar asked Dec 02 '22 08:12

Eduardo Marinho


1 Answers

Validate at input time. Validate again before you put it in the database. And have database constraints to prevent bad input. And you can bet in spite of all that, bad data will still get into your database, so validate it again when you use it.

It seems like every day some web app gets hacked because they did all their validation in the form or worse, using Javascript, and people found a way to bypass it. You've got to guard against that.

Paranoid? Me? No, just experienced.

like image 136
Paul Tomblin Avatar answered Dec 04 '22 05:12

Paul Tomblin