Ajax to create password hash
Posted by: greenman
Posted on: 2009-08-04 10:19:00
The unique username verification works, so I'm not asking about that.
Javascript doesn't do md5, so I'm attempting to farm it out with ajax here.
I can't seem to get the syntax right for the part in blue.
I'm a rank beginner in javascript, so I could use a little help here.
<script type="text/javascript">
// Test to see if there is an existing user by this name...
$(document).ready(function() {
$('#myIDLoading').hide();
$('#myID').blur(function(){
$('#myIDLoading').show();
$.post("../assets/scripts/check.php", {
myID: $('#myID').val()
}, function(response){
$('#myIDResult').fadeOut();
setTimeout("finishAjax('myIDResult', '" escape(response) "')", 400);
});
return false;
});
//Create md5 hash from string in field 'password2' and put it into hidden field 'password'.
$('#password2').blur(function(){
$.post("../assets/scripts/hashpass.php", {
password2: $('#password2').val()
}, function(response){
$('#password').val(response);
});
return false;
});
});
function finishAjax(id, response) {
$('#myIDLoading').hide();
$('#' id).html(unescape(response));
$('#' id).fadeIn();
} //finishAjax
This is my php code in hashpass.php:
<?php
$password2 = $_POST['password2']; // get the password
$password2 = trim(htmlentities($password2)); // strip some crap out of it
$myHashedPass = md5($password2);
return $myHashedPass;
?>
From the form that where the fields exist:
<input name="password2" id="password2" type="text" value="" size="32"/>
<input name="password" id="password" type="text" value=""/>
How do I word it so the hashed password gets inserted into hidden field 'password' on blur?
For purposes of diagnostics, I've left password as type="text".
Cheers.