Friday, May 18, 2012

How A Login Form Works

Hello Friends, enough of me giving you lectures about SQL Queries, lets now speak something that might interest you.

As you might know, in IT world, every Output, is a result of some input and some processing.

Lets now look at a page where we have a place to type something(input), internally some processing happens based on which we would get a result.

I will speak about the processing later, but the first things first.

Lets have a close in the "form" section of a Web Page.

<form method="post" action="/validate.php">
Username: <input type="text" name="uname" />
Password: <input type="password" name="upassword" />
<input type="button" value="Login" name="login" />
</form>

[Note: I assume you know some HTML codings]

The above <form> section will have the below look


Username:

Password: 



So, basically when user types in the username and his password and clicks on the Login button, it executes a PHP script, to validate the input, based on which an output would be displayed.

So once the login button is pressed, PHP or ASP script would run behind to connect to a Database, lets assume here MySQL Database.


I will show the PHP script that connects to Database Later.

Lets try to understand with the help of SQL query that PHP script executes.

So lets say it connects to a Database, to a table named "users"

Table: users

name           password
whiskey        abc@123
Admin        d0nth@ckm3

The PHP script would execute the below SQL Query

SELECT * FROM users
WHERE
name = "Whatever_userInputs"
AND
password = "Whatever_userInputs"


So now if the user inputs "name" as "whiskey" and "password" as "123@abc", this would return False, to get the value as True, both the name and password has to match in the "users" Table.

And lets say its coded as if the Value of Query is True, it would login the user, otherwise it would not.

Interesting isn't it.... Well I hope this gives you a basic idea what happens behind the curtain.

This is just a basic foundation, and thats all for this post. Dont Forget to check my next post.

Thank You!

0 comments:

Post a Comment