0
0
PHPprogramming~15 mins

Password hashing with password_hash in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
Password hashing with password_hash
📖 Scenario: You are building a simple user registration system. To keep user passwords safe, you need to convert plain text passwords into secure hashed versions before storing them.
🎯 Goal: Create a PHP script that hashes a given password using the password_hash function with the default algorithm.
📋 What You'll Learn
Create a variable to hold the plain text password.
Create a variable to store the hashed password using password_hash.
Use the default hashing algorithm.
Print the hashed password.
💡 Why This Matters
🌍 Real World
Web applications need to store user passwords securely to protect user accounts from theft or misuse.
💼 Career
Understanding password hashing is essential for backend developers and security engineers to build safe authentication systems.
Progress0 / 4 steps
1
Create a plain text password variable
Create a variable called $password and set it to the string "MySecret123".
PHP
Need a hint?

Use the = sign to assign the string to the variable.

2
Hash the password using password_hash
Create a variable called $hashedPassword and set it to the result of password_hash called with $password and PASSWORD_DEFAULT as arguments.
PHP
Need a hint?

Use password_hash($password, PASSWORD_DEFAULT) to create the hash.

3
Print the hashed password
Use echo to print the variable $hashedPassword.
PHP
Need a hint?

The output should start with $2y$ which is the prefix for bcrypt hashes in PHP.

4
Complete script to hash and display password
Combine all previous steps into a complete PHP script that sets $password, hashes it into $hashedPassword, and prints the hashed password.
PHP
Need a hint?

Run the script to see the hashed password printed.