Avançar para o conteúdo principal

Security in PHP web pages

One concern that must be present in all Web developers is the security of their products.

In this article we start a series of articles which will explore some basic security issues related to injecting SQL statements into web forms or URL parameters.

Examples of code with security issues and how to avoid them are presented.

So let's start with a simple login form implemented with the following code:




In this example, the code checks to see if more than one database record has been returned, thereby assuming that the credentials provided are correct.

The biggest mistake involves concatenating the values ​​received from the form with the SQL statement, thus allowing the user to manipulate the instruction to his or her own pleasure.

Regardless of the user name entered, simply type in the password the following text if you choose to indicate that the login has been successfully completed: o' or 1=1 #

With this text the SQL statement will always return a record because 1 equals 1. The # at the end lets you ignore the rest of the statement as it is the symbol for comments in MySQL.

The solution to this problem is to use parameters, preparing the statement before executing it. So the following code resolves this problem:





Comentários

Mensagens populares deste blogue

Let's make a car in Unity 3D

In this post we will make a simple car in Unity 3D. The Unity 3D physics engine is used in order to give the car a real behavior. This are the steps: [1] - Create a new Project

PacMan 3D

In this post we will be making a simple and classic game, the Pacman, with Unity 3D. Let's create a new a new project

Upgrading Windows 10 Home to Pro

 So I have been thinking about upgrading my Windows 10 Home Edition to the Pro version, but I always get to the point where it seems that I had to reinstall the entire SO and quit. After some investigating I have done it this way: - following this post  on the microsoft site I use one of the default keys for Windows 10 Pro and went to Settings > Update & Security > Activation > Change the product key; - next, Windows will activate the Pro functionalities and asks to restart; - now you have the Pro version but it's not activated, so you have to buy a Windows Pro Key. I went to UR cdkeys  and bought a key for less then €20; - and with the new key went to Change the product key and activated; - and it's done. Disclaimer : I have nothing to do with UR cdkeys so you can use any site to buy you cd key and your experience may vary from mine.