How to encrypt password in PHP

If you are developing a password protected site, you will have to decide the way to store passwords in your database.

If you store passwords in plain text and your database gets compromised, all your user logins will be exposed.

You may use the PHP MD5 function to encrypt your password; however, with the free tools available online, it can be cracked in matter of minutes.

Double or triple encryption using MD5 does not really help.

The Solution is pretty simple. Use password_hash function to encrypt the password. password_hash creates a new password hash using a strong one-way hashing algorithm



$Password = "Password";

$EncPswd = password_hash("rasmuslerdorf", PASSWORD_DEFAULT);