Results 1 to 5 of 5

Thread: Validating Password Confirmation Fields on a Form

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    1

    Exclamation Validating Password Confirmation Fields on a Form

    I am creating a user registration page for a project i am doing and I am having difficulty validating the password fields, i believe the problems lies with the specified input type. The code i am using works with text type inputs but does not seem to recognise password types. Does anyone have any suggestions other than making the password fields text fields. Below is an example of the IF THEN ELSE statements i am using....

    <!-- Option Explicit
    dim validation
    dim header
    header = "Pizza Organic"
    Function MyForm_OnSubmit
    validation = True

    If (Document.MyForm.Password.Value) <> (Document.MyForm.ConfirmPassword.Value) Then
    MsgBox "Your confirmation password does not match your orginal password, please correct this!",8, Header
    validation = False
    End If

    If validation = True Then
    MyForm_OnSubmit = True
    Else
    MyForm_OnSubmit = False
    End If
    End Function
    -->

    Thanks

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    I would suggest you use ClientSide JavaScript to do your form validation as it is supported by almost all browsers. Its not adviseable to use client side VBScritpt or Server Side script for form validation as it involves going back and forth to the server.

    Here is an example of your code in javascript:

    VB Code:
    1. <script>
    2. function Validate()
    3. {
    4.     var d=document.frmRegister;
    5.  
    6.  
    7.         if (d.txtPassword.value=="")
    8.         {
    9.         alert("Please enter a Password");
    10.         d.txtPassword.focus();
    11.         return false;
    12.         }
    13.  
    14.         if (d.txtPassword2.value=="")
    15.         {
    16.         alert("Please confirm the Password");
    17.         d.txtPassword2.focus();
    18.         return false;
    19.         }
    20.  
    21.         if (d.txtPassword.value != d.txtPassword2.value)
    22.         {
    23.         alert("Two typed password dont match");
    24.         return false;
    25.     }
    26.  
    27.     return true;
    28. }
    29. </script>

    To use this
    VB Code:
    1. <form name="frmRegister" method="post" onSubmit="return Validate()" action="register.asp">

    Put two password field called txtPassword and txtPassword2

    Hope this helps

    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Its not adviseable to use client side VBScritpt or Server Side script for form validation as it involves going back and forth to the server.
    I disagree. You must validate all user generated input (including HTTP headers, etc) Server side. Doing it client-side as well can speed things up, but doing only client-side data validation is as good as doing no data validation from a security standpoint.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  4. #4
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Can you explain further why we "MUST" validate "ALL" user generated input.
    Are there malicious users out there? You cannot trust any data the user has an opportunity to construct themselves. Read some books/articles on hacking for the clever stuff crackers come up with. One of my favorites is someone who had a script that ran a Unix shell command based on the Host Name - the cracker set up a fake DNS entry so that the host name resolved from his IP Address was the Unix equivalent to "format c:\".
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  5. #5
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by JoshT


    Are there malicious users out there? You cannot trust any data the user has an opportunity to construct themselves. Read some books/articles on hacking for the clever stuff crackers come up with. One of my favorites is someone who had a script that ran a Unix shell command based on the Host Name - the cracker set up a fake DNS entry so that the host name resolved from his IP Address was the Unix equivalent to "format c:\".
    Thanks for the advice josh!! infact PC security is one of my major area of study and have done a lot of reasearch on this issue as you suggested, specially on Viruses and Hacking as you mentioned. Hoping to do further study on this area.

    Anyway, I am not sure your example of fake DNS entry is really relevent here, as we are talking about form Validation. If you are talking about people miss using the scripts then you are right. Thats why we have to be careful how we write the script and dont leave any major holes for the hackers. There will be always people will take advantage of these issue and to be honest ASP has never been considered secure enough. You wouldnt see too many bank sites using ASP. Most uses JSP/Servlet.

    Also it depends on what kind of input we are dealing with. Like i said before there is no point of sending data to server just for the simple validation.

    As for transferring all the data to the server as you mentioned, the TCP/IP packets can be grabbed by anyone unless you are transmitting them securely.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width