9951 explained code solutions for 126 technologies


php-mysqlHow to hash a password in PHP and MySQL?


Hashing a password in PHP and MySQL is a secure way to store user passwords. It is done by using a one-way hashing algorithm to convert the plain text password into a random string of characters.

Example code

$password = 'mypassword';
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

Output example

$2y$10$VX3/3VX3VX3VX3VX3VX3VX3VX3VX3VX3VX3VX3VX3VX3VX3VX3

Code explanation

  • $password: This is the plain text password that needs to be hashed.
  • password_hash(): This is the PHP function used to hash the password.
  • PASSWORD_DEFAULT: This is the algorithm used to hash the password.

Helpful links

Edit this code on GitHub