MongoDB Authentication Using PHP

Date Posted: August 30, 2016, 6:25 pm

Recently, a client of mine wanted to have an authentication system for their existing Web Application. They are currently using MongoDB as their Database and just wanted to implement a simple Login, Register and Account page for their customers.

I did not have much experience working with MongoDB before I accepted the project  so I struggled a little bit figuring out a way to make an authentication work with MongoDB, but soon after – I realized that the focus of the logic should be on PHP itself, not MongoDB. So then I started coding until I finally finished a simple session based authentication.

Instead of pasting the entire code in this page, I decided to put the project on Github.



  • Registration page
    • Validations
    • Easy to scale fields.
    • Login and redirects on success
  • Login Page
    • Validations
    • Redirects on succes
  • Account Page
    • It simply displays the information of the user.
  • Logout


  • is_user_logged_in();
    • Returns true if the user is logged in, otherwise it returns false.
  • current_user();
    • Returns an object containing data of the currently logged in user.

About author

Carl Victor Fontanos

A fine gentleman specializing in front-end and back-end development with extensive experience building high performance web applications that keeps users engaged and help businesses grow.

Hire Me