Hello I'm working through a tutorial right now and there is a vague portion of the article regarding applying JavaScript to the form. I was hoping someone here could shine some light on the subject.
Basically I have registration form that is supposed to have its password hashed by JavaScript then handed off to my PHP code to pass the hashed password into MySQL.
The error I get is "Undefined index: p"
Here's my javascript:
Code: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(); }
Here's the PHP:
Here's the HTML:PHP Code:<?php
// The hashed password from the form
$password = $_POST['p'];
// Create a random salt
$random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
// Create salted password (Careful not to over season)
$password = hash('sha512', $password.$random_salt);
// Add your insert to database script here.
// Make sure you use prepared statements!
if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt) VALUES (?, ?, ?, ?)")) {
$insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);
// Execute the prepared query.
$insert_stmt->execute();
}
?>
HTML Code:<form action="process_login.php" method="post" name="login_form"> <table width="335" border="0" align="center"> <tr> <td>Madisontshirt ID:</td> <td ><input type="text" name="email" style="width: 225px;" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" id="password" style="width: 225px;" /></td> </tr> <tr> <td> </td> <td><div align="right"> <input type="button" value="Login" onclick="formhash(document.createElement("input");" /> </div> </form></td> </tr>


Reply With Quote
Bookmarks