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.

Dani AI

Generated

Brief clarification and a few practical follow-ups.

The visible blank inputs in IE are exactly the behavior reported by : older Internet Explorer builds will not convert an <input> from one type to another after it’s already in the document. Creating an input element, appending it, then trying to change its type leaves a normal textbox visible in IE while other browsers update the element. That explains the symptom and confirms the fix found by ; it also validates ’s debugging suggestion to use the IE dev tools.

Options and tips that weren’t spelled out in the thread:

  • The simplest cross‑browser approach is to set the name, type (hidden) and value on the element before appending it to the form.
  • If older IE refuses to accept type even before append, prefer reusing a hidden input already present in the HTML (set its value at submit time) or insert a small HTML snippet (innerHTML / insertAdjacentHTML) rather than relying on nonstandard tricks.
  • The p that asked about is just the form field name — on the server side the hashed password arrives as that parameter.

Security and robustness notes:

  • Client-side hashing (sha512.js) can help, but it is not a substitute for server‑side protections. Always use HTTPS and store passwords with a modern server-side algorithm (bcrypt/Argon2 or PHP’s password_hash), with proper salts. Clearing the plaintext password before submit is good practice. Verify (as suggested) that the hashing script is compatible with the IE versions targeted.

Quick checklist: set attributes before append, test with IE’s F12 console, prevent multiple appends on repeated clicks, and handle authentication hashing on the server.

Recommended Answers

All 9 Replies

in internet explorer check the activex object settings

Thank you Rithish for consideration. Can you be bit more specific

What error do you get? In IE, open developers tools (F12), go to the Script tab and start debugging.

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

What do you mean by:

p.name = "p";

?

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.

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.

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

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); 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.