Table of contents
Hashing is the process of altering or changing a piece of data into another form in an attempt to obfuscate it.
Use Cases and Examples
A good example is hashing user passwords before storing them in the database. By hashing the password anyone with access to the database can only see the hashed version and not the actual password. This means if the database ever gets leaked the actual password the user provided will remain unknown.
This does two things, one prevents the intruder from being able to use the password to access the system and also prevents the intruder from being able to test the password against other systems. Thus if the user used the same password on a different system.
01: echo password_hash("text", PASSWORD_DEFAULT); // $2y$10$.Dpb2GdvuHBwrwS53PuRBuWc1tKzRS.1/IQjK1QPKHJAYV1xYQplW
02: echo password_verify("text2", "$2y$10$.Dpb2GdvuHBwrwS53PuRBuWc1tKzRS.1/IQjK1QPKHJAYV1xYQplW") //false
The above code shows an example of hashing in PHP [↗]. On line
password_hash function is used to hash the provided password in this case
text using the
bcrypt hash algorithm which is the default for the PHP
02 we use the
password_verify function to very if
text2 is related to the hash string and we get
false since that hash string was generated using
text and this is how a system can tell if its the right user. Thus by comparing the password the user enters every time to the hash string that is stored in the database.
Hashing provides a way to hide and secure information from prying eyes and relies on cryptographic algorithms to achieve this.
Here is another article you might like 😊 "What Is High Level?"