Skip to content
Advertisement

php mongodb validate form password

This is my first time using mongodb with php and I have a register and a login form . When a user registers I succesfully hash his password using password_hash() php function and insert it in a mongodb collection . However when I login and insert a password I want to check if inserted password corresponds to a hashed password in the collection using password_verify()

I cannot find the correct syntax to iterate through the collection and check if a hashed password matches with the given password when I login .

My code :

JavaScript

Advertisement

Answer

If you like to use the password_verify() function then I guess you have to run it like this:

JavaScript

Or with a single query:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement