4

I allow users to register on my website using a registration form. Once form is submitted a token will be generated and will be sent by email to user, they need to click on the token link to activate their account.

My question is that if I do it, do the malicious codes can still send multiple emails to my website to register, should I use Captcha to protect the website or there is any other method ?

Jack
  • 6,430
  • 27
  • 80
  • 151
  • 1
    did you implement all "registration" flow, and "forgot password" etc by yourself? I've written (java, on Spring Security) an open-source project that does that. have a look: http://auth-flows-demo.appspot.com/ – OhadR Apr 25 '14 at 08:21
  • 1
    http://webdesignledger.com/tips/why-you-should-stop-using-captchas. – Aleksandr M Apr 29 '14 at 10:24
  • 1
    @OhadR, too bad, I moved to Java EE frameworks. This would have been nice if it could work without the use of Spring Security. By the way, I have done the same only using Java EE solution. – Buhake Sindi Apr 29 '14 at 21:40

5 Answers5

7

If all you want is to prevent double submissions, you can generate a unique token for the form that you check on submission. This requires some thought if there are multiple forms per page. Also, a simple method is to just disable the form/button on submission. This is even more effective if the form is submitted via Ajax (so that the action parameter of the form can be absent and thus not easily harvestable).

If you want to prevent automatic submissions (by bots), while Captcha is probably the strongest of the common methods, it is also very user-hostile. Instead, unless you have a reason to believe your site is being specifically targeted, it is usually enough to just use honey-pot fields (invisible fields that a human would never fill but a bot would) and hidden fields that you fill with a known value after a short delay using JS (a bot wouldn't normally execute JS nor take time to type into fields like a human). Simply doing an Ajax submission is also usually enough. I recommend using one or a mixture of these methods before falling back to Captcha.

kaqqao
  • 12,984
  • 10
  • 64
  • 118
  • Even though I agree with you about Captcha being user unfriendly (I wouldn't go as far as calling it hostile), people are pretty much used to it by now, and since registration is a one time event, I believe that it's very much accepted nowadays. – ethanfar Apr 30 '14 at 10:21
  • I think it also depends on the implementation. Simple numbers-only Captchas are way more tolerable than ones using lower and upper case characters, numbers and all in different colors. – kaqqao Apr 30 '14 at 10:28
2

Captcha is one of the standard methods.

Another way is do not do a direct submit of the form.Use AJAXfied server calls sos that form does not get posted by itself but has some data scrambling of inner fields & delays the submissions.

$("#contactForm").submit(function(event) 
 {
     /* stop form from submitting normally */
     event.preventDefault();

     /* get some values from elements on the page: */
     var $form = $( this ),
         $submit = $form.find( 'button[type="submit"]' ),
         name_value = $form.find( 'input[name="name"]' ).val(),
         email_value = $form.find( 'input[name="email"]' ).val(),
         phone_value = $form.find( 'input[name="phone"]' ).val(),
         message_value = $form.find( 'textarea[name="message"]' ).val();


     /* Send the data using post */
     var posting = $.post( "contact-form-handler.php", { 
                       name: name_value, 
                       email: email_value, 
                       phone: phone_value, 
                       message: message_value 
                   });

     posting.done(function( data )
     {
         /* Put the results in a div */
         $( "#contactResponse" ).html(data);

         /* Change the button text. */
         $submit.text('Sent, Thank you');

         /* Disable the button. */
         $submit.attr("disabled", true);
     });
});</script>
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Rohitdev
  • 866
  • 6
  • 15
0

I'm no expert in this matter, but the solution seems rather obvious to me:

Everyone uses CAPTCHA. There's simply no other way to protect your server from automated attack. It won't save you from DDoS, but will handle pretty much everything else because CAPTCHA is, well, CAPTCHA.

You do have multiple CAPTCHA solutions available though, so choose one that suits you best.

velis
  • 8,747
  • 4
  • 44
  • 64
0

As Velis mentioned, easiest way is to use Captcha.

Other solutions exist but can be easily beaten if bots are targeted for your website, for example, having an hidden field like "re-enter email" which will be filled by bots, but can be caught on the server side and registration can be rejected.

Certain, complicated methods also exist, like recording mouse clicks or time taken to fill the form, but these require significant JS work and can be overkill until your website becomes a bot target.

Varun Achar
  • 14,781
  • 7
  • 57
  • 74
0

Captcha is one plausible solution, but most humans don't like it. How about instead if you add some intelligence to your system? Implement a cooldown between emails. Before sending an email, wait one minute. If another email request comes then wait another minute and don't send the first one. (This could be another form of attack but only if this is the only line of defense). Would a person try to register 30 times in the last minute? No. Would a person re-register if the last register was successful? No. You can also combine these with the IP of the registering user: Would a user try to create 10 new account for other users from the same IP in 10 minutes? Unlikely.

If this is a corporate website and you MUST prevent the email spamming, then consider secondary ways of communication. For example, if you have the means, you can request the user to SMS the email address to a specific number, which would create a reset password request.

You could also, upon the user completing the registration, generate a list of numbers that should be used to retrieve the account. Something like: "If your account is lost, it can be retrieved by entering one of these numbers into the RETRIEVE field" And then provide a list of numbers that would be confidential to your company and the customer. The same way Google does it.

Although these mechanisms can become complex, they will be smarter than any captcha; will be easier to adapt, and more comprehensive. On the plus side your users will thank you for not having to read twisted images of numbers and letters.

Alexandre Santos
  • 8,170
  • 10
  • 42
  • 64