.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Secure Web Application Development

Posted By:Shashi Ray       Posted Date: December 24, 2009    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  
 

Secure Web Application Development

Lab Exercises

  1. The steps 2- 7 can be done using Visual Studio 2003 and above. For Java and other applications coding may be done on similar lines.
  2. Make a web asp.net project. Prepare a Feedback form for visitors of your web site. Name the form as guestbook.aspx. The form should be as shown below.
  3. Right click the page in Solution explorer of your Visual studio and select Set as Start Page. Build and Run the form. 
  4. Enter in each of the fields and submit form. View the results. ( The page succeeds in Posting the Feedback)



Apply Input Validations:

  1.  Now, Add the class FieldValidation.vb as in Appendix - I to your project.
  2. Doubleclick the Submit button and go to View code. Enter the code as given in the Appendix - II.
  3. Build and Run
  4. Enter in each of the fields and submit form. Now View the results. ( The page should not succeed in Posting the Feedback)


Note the difference in behaviour of the application is step 3 and step7.



Appendix - I
FieldValidation class library 
FieldValidation.vb



Imports System
Imports System.Uri
Imports System.Exception
Imports System.Xml
Imports System.Drawing
Imports System.Text
Imports System.Text.RegularExpressions

Imports System.IO


  Public Class FieldValidation

  
  Dim CodeLtrs As String
  Dim CodeNms As String
  Dim CodeChs As Integer
  Dim LtrArr As Char()
  Dim NmArr As Char()
  Public Enum FaultCode
  Client = 0
   Server = 1
  End Enum
  


  
  ' "Required Field Validation"
  Public Function Field_Entered(ByVal field As String) As Boolean
  Try
  If field.Length = 0 Then
  Return False
   Else
  Return True
  End If
  Catch ex As Exception

  End Try
  End Function
  'General Validation for all Types Of Fields

  Public Function Validate(ByVal field As String, ByVal MinSize As Integer, ByVal MaxSize As Integer, ByVal check As String) As Boolean
  Dim i, j As Integer
  Dim ch As Char
  Dim flag As Boolean = True
  Try
  For i = 0 To field.Length - 1
  ch = field.Chars(i)
  j = 0
  If field.Chars(i) = Chr(13) Then  'Checking For Enter Key Pressed
  i = i + 1
  Else
  For j = 0 To check.Length - 1
   If ch = check.Chars(j) Then
  Exit For
  End If
  Next
  End If
  If j = check.Length Then
  flag = False
   Exit For
  End If
  If field.Length > MaxSize Or field.Length < MinSize Then
  flag = False
  Exit For
  End If
  Next
   Catch ex As Exception


  End Try
  Return flag
  End Function
  'Validates the String Of Any Type

  Public Function String_Correct(ByVal field As String, ByVal MinSize As Integer, ByVal MaxSize As Integer, ByVal check As String) As Boolean
  'Defintion Of A String That It Can Contain
  Try
  If Validate(field, MinSize, MaxSize, check) Then
  Return True
  Else
  Return False
   End If
  Catch ex As Exception


  End Try
  End Function
  'Validates the Alphanumeric Value

  Public Function Alphanum_Correct(ByVal field As String, ByVal MinSize As Integer, ByVal MaxSize As Integer, ByVal check As String) As Boolean
  Try
  If Validate(field, MinSize, MaxSize, check) Then
  Return True
  Else
  Return False
  End If
  Catch ex As Exception


   End Try
  End Function
  ''Validates the Password
  Public Function Password_Correct(ByVal field As String, ByVal MinSize As Integer, ByVal MaxSize As Integer, ByVal check As String) As Boolean
  Try
  If Validate(field, MinSize, MaxSize, check) Then
  Return True
  Else
  Return False
  End If
  Catch ex As Exception

  End Try
  End Function
  'Validates the Numeric Value

  Public Function Numeric_Correct(ByVal field As String, ByVal MinSize As Integer, ByVal MaxSize As Integer) As Boolean
  Try
  If IsNumeric(field) Then
  If field.Length <= MaxSize Then
   Return True
  Else
  Return False
  End If
  End If
  Catch ex As Exception

  End Try
  End Function
  'Validates the Email

  Public Function Email_Correct(ByVal field As String) As Boolean
  Try
  Return Regex.IsMatch(field, "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")
  
  Catch ex As Exception

  End Try
  End Function



 


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend