SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2004
    Location
    USA
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript, Forms, and MD5

    I have the MD5 script but now need to get the password parameter hashed by the MD5 before I post it to my jsp file for processing in the database.

    How would I get the java script code to create the hashed password and then pass it as a parameter to the jsp along with the other parameters?

    This is the function that creates the hash.
    hash = hex_md5("input")


    Here is the code I have so far.

    Thanks


    <HTML>
    <HEAD>
    <TITLE>Add a New Person</TITLE>
    <script language="JavaScript" src="md5.js"></script>
    </HEAD>
    <BODY>


    <FORM ACTION="Saveperson.jsp" method="post">
    <TABLE>
    <TR>
    <TD>First Name/TD>
    <TD><INPUT TYPE="text" NAME="firstname"></TD>
    </TR>
    <TR>
    <TD>Last Name/TD>
    <TD><INPUT TYPE="text" NAME="lastname"></TD>
    </TR>
    <TR>
    <TD>User Name/TD>
    <TD><INPUT TYPE="text" NAME="username"></TD>
    </TR>
    <TR>
    <TD>Password/TD>
    <TD><input type = "password" name = "password"></TD)
    </TR>

    <TR>
    <TD COLSPAN="2" ALIGN="RIGHT">
    <INPUT TYPE="submit" VALUE="Submit" >
    </TD>
    </TR>
    </TABLE>

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

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you call a function onKeyUp in your password field which MD5s the content of the password field and stores it in a hidden field?
    Then your jsp would use the value from the hidden field instead of the password field.

    Alternatively - instead of submitting the form directly - your submit button could call a function which converts the value and then submits the form using form.submit.

    Am I just making this over-complicated? There's probably a much simpler solution, right?


    Andy
    From the English nation to a US location.

  3. #3
    SitePoint Member
    Join Date
    Feb 2004
    Location
    USA
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found some information through looking at some login code of other sites. If I call a function when the submit button is pressed to take the value password and MD5 it then store it in the form under a hidden value called final_pass, would that work. He's the code im working on. Thanks again, my professor is of little help.

    <HTML>
    <HEAD>
    <TITLE>Add a New Person</TITLE>
    <script language="JavaScript" src="md5.js"></script>
    </HEAD>
    <BODY>


    <SCRIPT language="JAVASCRIPT" >

    function validate_form(form)
    {
    var passwd_enc = hex_md5(form.password.value);
    form.finalpass.value = passwd_enc;
    return true;
    }

    </SCRIPT>

    <FORM ONSUBMIT="return validate_form(this)" METHOD="POST" ACTION="Saveperson.jsp" method="post">
    <INPUT VALUE="" NAME="final_pass" TYPE="HIDDEN">

    <TABLE>
    <TR>
    <TD>First Name/TD>
    <TD><INPUT TYPE="text" NAME="firstname"></TD>
    </TR>
    <TR>
    <TD>Last Name/TD>
    <TD><INPUT TYPE="text" NAME="lastname"></TD>
    </TR>
    <TR>
    <TD>User Name/TD>
    <TD><INPUT TYPE="text" NAME="username"></TD>
    </TR>
    <TR>
    <TD>Password/TD>
    <TD><input type = "password" name = "password"></TD)
    </TR>
    <TR>
    <TD COLSPAN="2" ALIGN="RIGHT">
    <INPUT TYPE="submit" VALUE="Submit" >
    </TD>
    </TR>
    </TABLE>
    </FORM>

    </BODY>
    </HTML>


Bookmarks

Posting Permissions

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