This tutorial will tell you how to secure your web pages through Image Security.
1. As first step create some images in photoshop as shown below:|
| |
| 2. Now Create a database named as SecImages. Then create a table with three fields:|
| |
|
| |
| |
| Here in ImageName field enter image name with its extension and in ImageValue field store image value. The value of this field should be the same as original image value.|
| CODING PART:|
| Create an .asp page named ImageSecurity.asp. |
| Open Database: | |
| <%
Dim sqlt, objConn
Dim strConnect
Dim rs
Dim OriginalValue,image
strConnect= "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Inetpub\wwwroot\SecImages.mdb"
Set objConn=Server.CreateObject("ADODB.connection")
objConn.Open strConnect
' Connection string and SQL statement
strConnect.CursorLocation = 3
response.buffer=true
%>
| |
| |
|
| 4. Now pick random image from database with the help of random function |
| <%
dim intRnd
sqlt = "select * from Table1" ' Your Table Name
Set rs = strConnect.execute(sqlt)
' Generating random number from total number of records
Randomize Timer
intRnd = (Int(RND * rs.RecordCount))
rs.Move intRnd
' Showing the random statement
image=rs.Fields("IamgeName")
response.write "<img src="&image &_
">"
%> | |
| |
| Declare a variable intRnd to hold the random record number. Randomize Timer statement is used to initialize the random-number generator. Then RND Function is used to generate a random number between 1 and total number of records availabe . |
| Once we have got a random number between 1 and total number of records, we can move the Recordset Cursor to that random record by using Recordset. Then we show the random image from database.|
|
|
| IMAGE VALUE:|
| <input name="imageoriginalvalue" type="hidden" id="imageoriginalvalue" value= <% OriginalValue=rs.Fields("ImageValue")
Response.Write(OriginalValue)%>> | |
| | Now in hidden field we hold image original value from our database. This value will use to ensure that a user enter a correct value. |
| | ERROR:|
| | <% if Request("Error")="True" then
Response.Write("<b><font size=""4"">You have entered a Wrong Security Code!</font></b>")
else
response.Write("<strong>Please fill the following Details</strong>")
end if
%> | |
| | Here we handle Error part. if user enter a wrong code then a message will show.|
| | PROCESS PART:|
| | After submitting form, we will check that user enter a correct image value or not. Create another .asp named ImageSecurityProcess.asp|
| | CODING FOR IMAGESECURITYPROCESS.ASP|
| | <%
SecCodeOriginal=Request.Form("imageoriginalvalue") 'Hidden field Value
SecCodeUser=Request.Form("imagevalue")
Name=Request.Form("Name")
EmailAddress=Request.Form("EmailAddress")
if SecCodeOriginal=SecCodeUser then
response.Write("<strong>You have entered a correct image code.<strong>")
else
response.Redirect "ImageSecurity.asp?Error=True"
end if
%> | |
| | Here we declare SecCodeOrigianl variable for holding original image value from database and SecCodeUser for code that user have entered. |
| | In if condition we check that whether the image orignial value is equal to user value or not, if Yes then a message will show or if No then it will redirect to ImageSecurity.asp page with Error value. Error part is already mention above.|
| | For Demo Click Here [Download Source]|
|
discuss this topic to forum