Hashing passwords in PHP

Date:     Updated:

Categories:

Tags:

Hasing user passwords using PHP function ✏️



1. Why is it important?


🔔  Privacy  


2. password_hash()


🔔  .  
// syntax
$encrypted_password = password_hash($password, PASSWORD_DEFAULT);

(1) PASSWORD_DEFAULT : Use the bcrypt algorithm (default as of PHP 5.5.0). Note that this constant is designed to change over time as new and stronger algorithms are added to PHP. For that reason, the length of the result from using this identifier can change over time. Therefore, it is recommended to store the result in a database column that can expand beyond 60 characters (255 characters would be a good choice).

(2) PASSWORD_BCRYPT : Use the CRYPT_BLOWFISH algorithm to create the hash. This will produce a standard crypt() compatible hash using the “$2y$” identifier. The result will always be a 60 character string, or false on failure.

(3) PASSWORD_ARGON2I : Use the Argon2i hashing algorithm to create the hash. This algorithm is only available if PHP has been compiled with Argon2 support.

(4) PASSWORD_ARGON2ID : Use the Argon2id hashing algorithm to create the hash. This algorithm is only available if PHP has been compiled with Argon2 support.


3. password_verify()


🔔  Return True or False  
// syntax
$isMatch = password_verify($password, $input);  


4. Encrypte vs Hash


🔔  .    

. Encryption is the process of scrambling plaintext into unreadable ciphertext, which you can decrypt with a relevant key. The intent is to pass the information to another party, and the recipient will use keys to decipher the data.

. Hashing turns plain text into a unique code, which can’t be reverted into a readable form. Hashing also scrambles data, but the intent is to prove its authenticity. Administrators can run a check on hashed data to determine the contents haven’t been touched or altered while in storage. No deciphering key exists.


References
PHP Official Document
PHP Official Document


🌜 This is my personal study blog. If you find any errors or mistakes,
  please feel free to point them out in the comments or via email. 💌
   I would greatly appreciate it! 😄✨💛

Go to Top

Other Posts In PHP

Leave a comment