0

I have the next HTML form:

<form name="register" method="post" action="register.php" >
<fieldset>
    <legend>Register</legend>
    <input type="hidden" name="regform" value="true" />

    <label for="username">Username:</label>
    <input type="text" name="username" id="username" />
    <br />
    <label for="email">Email:</label>
    <input type="text" name="email" id="email" />
    <br />
    <label for="password1">Password:</label>
    <input type="password" name="password1" id="password1" />
    <br />
    <label for="password2">Password:</label>
    <input type="password" name="password2" id="password2" />
    <br />

    <?php
    $config = new Config();
    $publickey = $config->getCaptchaPublicKey();
    echo recaptcha_get_html($publickey);
    ?>

</fieldset>
<input type="submit" value="Register!" />

What I'd like to do, is that when the user presses the submit button, i send the data from the forms via AJAX and verify them. But I was wondering how I update the recaptcha? I can verify it in my PHP script, and echo a new one included with the error. But how do I send this back to the client and let javascript (jQuery) replace the old reCAPTCHA with the new?

Hope someone can help me with this.

Greets,

Luxo

PS: Should I use a javascript encryption to encrypt the passwords before sending to the server?

Kaj
  • 2,445
  • 3
  • 23
  • 34
  • As to javascript encryption of passwords - checkout this question http://stackoverflow.com/questions/4121629/password-encryption-at-client-side – WTK Mar 25 '13 at 13:26
  • use https to secure your communication channel with server – Arun P Johny Mar 25 '13 at 13:30

2 Answers2

1

1) to request the image you must request the recaptcha with the correct headers in AJAX that is send the headers for requesting an image in your case

2) if validating through AJAX you must encrypt or otherwise any bum can touch the passwords for that just encrypt with the same encryption you would use to store in your database ex: if you encrypt with md5 from php instead encrypt the pwd with md5 using JS and send the hash

ManZzup
  • 526
  • 4
  • 12
0

If you use jQuery then $('#form-id').serialize(); is what you're looking for. Use the data returned from this function as data to post an Ajax.

If you don't have HTTPS then it is worthless to encrypt password with JavaScript.

flux
  • 183
  • 7
  • The question is not about how to POST an AJAX but how to "send this back to the client and let javascript (jQuery) replace the old reCAPTCHA with the new". – Adrian Godong Mar 26 '13 at 07:11