Which PHP function is used to hash passwords securely? a) md5() b) crypt() c)…
- User
Which PHP function is used to hash passwords securely? a) md5() b) crypt() c) password_hash() d) hash()
Assistant
The correct answer is:
c) password_hash()Explanation:
password_hash()is the recommended and secure way to hash passwords in PHP. It uses strong hashing algorithms like bcrypt (by default) and automatically generates a secure salt.
Example:
$hashed = password_hash('my_password', PASSWORD_DEFAULT);-
md5()andhash()are general-purpose hashing functions, but they are not suitable for password hashing because they are fast and not designed to be resistant to brute-force attacks. -
crypt()can be used for password hashing, but it requires more manual setup (like choosing the algorithm and managing salts), makingpassword_hash()a safer and easier choice.
✅ Best Practice: Always use
password_hash()and pair it withpassword_verify()when checking passwords.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.