Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Cyber Security
  3. Question
Cyber Security

How does password_hash php work?

Asked by Amit Raj Apr 20, 2022 1.1K views 1 answer
Share

About this question

Why does this example from the PHP manual give different results every time it runs? echo password_hash("rasmus lerdorf", PASSWORD_DEFAULT); And then, password_verify() knows that ALL those hashes match "rasmus lerdorf"! It is like magic to me even the doc stated clearly:


Note that password_hash() returns the algorithm, cost and salt as part of the returned hash. Therefore, all information that's needed to verify the hash is included in it. This allows the verify function to verify the hash without needing separate storage for the salt or algorithm information.


This function is safe against timing attacks.


echo password_verify ( 'rasmus lerdorf' , '$2y$10$EMawXU7qNS4GzU2Do8bByeb7sSQZxecvmZ6mBrToxsOaY7RMAIGua' );  //=>true
echo password_verify ( 'rasmus lerdorf' , '$2y$10$0vMA2k7LxTBstI/J7clkkuZZ/XtuS1fklVuoM6sl4Fc/aj1avQa5u' ); //=>true
echo password_verify ( 'rasmus lerdorf' , '$2y$10$iuE2EzHMNONAWFKh/4Wyl.dcBxgFaNzAh32va0/gyE4ScqnNr/Uc.' ); //=>true

What is going on? How does password_verify() know some crazy string match 'rasmus lerdorf' but hackers don't?

Your answer

1 Answer

More Cyber Security discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Cyber Security Blogs

Guides, tips and career advice on Cyber Security from JanBask experts.