• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • About
  • Subscribe BMA
  • Contact Us!

Be My Aficionado

Inspire Affection

You are here: Home / Tutorials / Basic Authentication with PHP & MySQL

Basic Authentication with PHP & MySQL3 min read

June 3, 2016 by Varun Shrivastava Leave a Comment

Lately, I have been receiving a lot of emails on how to create a basic login and registration system by using plain PHP and MySQL. I have made this series just to teach you about the Basic Authentication, i.e. registering a user into the database and then logging the user to the system. We will also encrypt the password using PHP’s native function which uses the Bcrypt Algorithm. In a nutshell, this series will contain seven videos. What will you learn? At the end of this series, you will learn to create a basic authentication system for your application using PHP and MySQL.

  1. Create Database Schema and Folder Structure
  2. Create a Simple Login Page
  3. Create a Simple Registration Page
  4. Create Connection with the database
  5. Register User in the Database
  6. Authenticate User into the System
  7. Securing Pages from Invalid User

Topics Covered

  • Create Database Schema and Folder Structure
      • Step 1. Create a Database with the name tutorials
      • Step 2. Create a table inside the tutorials database with the name t_login
      • Step 3. Create Folder Structure to work with
  • Create a Simple Login Page
  • Create a Simple Registration Page
  • Create Connection with the Database
  • Register User in the Database
  • Authenticate User into the Database System
  • Conclusion

Create Database Schema and Folder Structure

Step 1. Create a Database with the name tutorials

create-database

Step 2. Create a table inside the tutorials database with the name t_login

--
-- Table structure for table `t_login`
--

CREATE TABLE `t_login` (
 `id` int(11) NOT NULL,
 `username` varchar(50) NOT NULL,
 `password` varchar(500) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `t_login`
--
ALTER TABLE `t_login`
 ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `t_login`
--
ALTER TABLE `t_login`
 MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

Step 3. Create Folder Structure to work with

folder structure

Create a Simple Login Page

Create a Simple Registration Page

 

Create Connection with the Database

The above code is used to create connection with the database. It uses PDO class, the PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. It is the preferred way for making connection to the database.

In this class, we create a constructor which holds the code for making connection to the database. As soon as the object of this class is created, it gets initialized and a connection to the database is made. A separate class for holding database connection and all the related business logic helps to maintain the modularity of the application.

Register User in the Database

Create a file with the name registerUser.php. The registerUser.php file lies inside process folder. This file is responsible for receiving the data sent from the registeration form with the help of $_POST superglobal variable. We pass the name of the input field we want to fetch the data from and save it to its corresponding variable.

Then we load the DBConnect.php class which resides inside classes folder and create its object. We use the object to access the function that we created inside of the DBConnect class.

Authenticate User into the Database System

Create a file named authUser.php inside your process folder and copy the code from the video in it.

Conclusion

I hope you learned the basic authentication successfully. If you have any problem or any query, then you may comment below. I will be very active to solve any of your queries and help you grasp each and every part of it.

For full tutorial series, visit our youtube channel, and don’t forget to subscribe.

If this article solved your query then share your token of love 🙂



One Life, Rise & Shine
Cheers 🙂

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • More
  • Click to print (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to share on Telegram (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Skype (Opens in new window)
  • Click to email this to a friend (Opens in new window)

Filed Under: Tutorials, Wordpress N SEO Tagged With: authentication, basic, database, mysql, php

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Featured Posts

Adsense Invalid Traffic took US $125

April 7, 2017 By Varun Shrivastava Leave a Comment

How to Increase Your Savings Without taking any Market Risks (Life Insurance)

September 1, 2018 By Varun Shrivastava Leave a Comment

A brief Introduction about Gradle

October 13, 2016 By Varun Shrivastava Leave a Comment

The New Gutenberg Editing Experience – Introducing a New Editing Experience for WordPress

July 8, 2018 By Varun Shrivastava Leave a Comment

How to Earn Money From Amazon Affiliate Network

May 6, 2018 By Varun Shrivastava Leave a Comment

Latest Posts

  • How To Become Financially Independent In India?
  • Trie Data Structure Implementation | (PUT, GET, DELETE)
  • 5 THINGS I WISH I KNEW When I Started Programming
  • 3 Best Laptops (Mid-Range) For Every Use Case In India
  • Distributed System Architectural Patterns

Categories

  • Blogging (104)
  • Cooking (11)
  • Fashion (7)
  • Finance & Money (13)
  • Programming (53)
  • Reviews (4)
  • Technology (22)
  • Travelling (4)
  • Tutorials (12)
  • Web Hosting (8)
  • Wordpress N SEO (18)

Follow us on facebook

Follow us on facebook

Grab the Deal Now!

Hostgator Starting @$3.95/mo

DigitalOcean Free Credits

Trending

Affordable Hosting amazon aoc-2020 bad luck believe in yourself best database earn money blogging education experience fashion finance Financial Freedom food friends goals google india indian cuisine indian education system java javascript life life changing love make money microservices motivation oops poor education system principles of microservices problem-solving programmer programming reality seo SSD Hosting success technology tips top 5 VPS web web developer wordpress

Footer

Copyright © 2021 · BeMyAficionado by Varun Shrivastava · WordPress

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.