-1

Hello All

I am trying to just test a simple javascript code.
Following Code is working very fine in FF-14, Google Chrome - 21, Safari - 3.2

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="sha512.js"></script>
<script type="text/javascript">
function formhash(form, password) {

   // Create a new element input, this will be out hashed password field.
   var p = document.createElement("input");
   // Add the new element to our form.
   form.appendChild(p);
   p.name = "p";
   p.type = "hidden"
   p.value = hex_sha512(password.value);
   // Make sure the plaintext password doesn't get sent.
   password.value = "";
   // Finally submit the form.
   form.submit();

}
</script>
<?php
if(isset($_GET['error'])) { 
   echo 'Error Logging In!';
}
?>

</head>

<body><form action="process_login.php" method="post" name="login_form">
   Email: <input type="text" name="email" /><br />
   Password: <input type="password" name="password" id="password"/><br />
   <input type="button" value="Login" onclick="formhash(this.form, this.form.password);" />
</form>
</body>
</html>

Where I am wrong...? Please guide me.

6
Contributors
9
Replies
17
Views
5 Years
Discussion Span
Last Post by VIDASOCIALfairfield
0

var p = document.createElement("input");
form.appendChild(p);

What do you mean by:

p.name = "p";

?

0

What do you mean by:
p.name = "p";
?

I think he is sending the password as 'p' (name of the input), and the password input goes blank.

0

Are you sure that your external JS file (sha512.js) contains functions that compatible with IE as well? I don't know what hex_sha512() does, so it is hard to say what causes it to stop working... What does IE error say? At least it may help you find the incorrect call (format) for IE.

0

Hello to All and thank you all for considering my problem.
I want a login form in php with MySQL and session with password encryption mechanism.

For this I am trying this example

I am not getting error but the code actually just creating a blank textbox in IE and appending them one after another. And p is the object which will hold the reference of newly created textbox at runtime which will hold the hashed value of password. Here you can find the complete algorithm of hashing algorithm sha512

0

OK I found the solution.

Its actually more an IE thing. IE doesn't like to change the type property of inputs once they've been appended to the document. The simple fix would be to just swap around the appendchild() call so it comes after the property settings.
Quoted Text Here

p.name = "p";
   p.type = "hidden"
   p.value = hex_sha512(password.value);
   form.appendChild(p); 
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.