How to Database-Driven User Authentication?

Ever have something that you wanted to put on the internet for only a group of
people to see? Well, then this script is for you. All you need is; PHP and MySQL.
Create a MySQL database to store the usernames and passwords.

CREATE TABLE auth_users ( 
  f_name varchar(50) DEFAULT '' NOT NULL, 
  l_name varchar(50) DEFAULT '' NOT NULL, 
  username varchar(50) DEFAULT '' NOT NULL, 
  password varchar(100) DEFAULT '' NOT NULL 
  );

Now that you have a table named auth_users, you can now create an interface to add First names, Last Names, usernames, and passwords.

  1. Type the following HTML:
  <HTML> 
  <HEAD>   
  <TITLE>Add a user</TITLE>   
  </HEAD>   
  <BODY>   
  <H1>Adding a Record to auth_users</H1>

2) Begin your form

 <FORM METHOD="post" ACTION="adduser.php">

3) Create an input field for the user’s first name with a text label:

  <P><B>First Name:</B> 
  <INPUT TYPE="text" NAME="f_name" SIZE=25 MAXLENGTH=50></P>

4) Create an input field for the user’s last name with a text label.

  <P><B>Last Name:</B>  
  <INPUT TYPE="text" NAME="l_name" SIZE=25 MAXLENGTH=50></P>

5) Create an input field for the username with a text label.

  <P><B>Username:</B> 
  <INPUT TYPE="text" NAME="username" SIZE=25 MAXLENGTH=50></P>

6) Create an input field for the username with a text label.

 <P><B>Password:</B>  
  <INPUT TYPE="text" NAME="password" SIZE=25 MAXLENGTH=25></P>

7) Add a Submit button

<P><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Add 
  User"></P>

8) Close your form and add some more HTML so that the document is valid:

 </FORM> 
  </BODY> 
  </HTML>

9) Save the file as show_adduser.html
Create the back-end script
1) Start the PHP block

10) Add this HTML:

 <HTML>   
  <HEAD> 
  <TITLE>Add a User</TITLE>   
  <BODY> 
  <H1>Added to auth_users</H1> 
  <P><B>First Name:</B> 
  <?php echo "$l_name"; ?></P> 
  <P><B>Last Name:</B> 
  <?php echo "$l_name"; ?></P> 
  <P><B>Username:</B> 
  <?php echo "$username"; ?></P> 
  <P><B>Password:</B> 
  <?php echo "$password"; ?></P>

11) Add a link back to the original form:

<P><A HREF="adduser.php">Add another</a></P>

12) Add some more HTML so that the document is valid:

  </BODY> 
  </HTML>

13) Save the file with the name adduser.php.
That’s it uploads and tries it out.