Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case-Sensitive Captcha Support #111

Closed
rautniraj opened this issue Feb 4, 2025 · 3 comments · Fixed by #113
Closed

Case-Sensitive Captcha Support #111

rautniraj opened this issue Feb 4, 2025 · 3 comments · Fixed by #113

Comments

@rautniraj
Copy link
Contributor

First of all, thank you for providing such a cool and easy-to-use library! Setting it up was seamless by following the GitHub repository and Ruby gem documentation.

I noticed that the library does not support case-sensitive captcha validation. While the captcha image displays text in uppercase, submitting the answer in lowercase is still accepted. After going through the code, I saw that the text is manually converted to lowercase before matching.

Could you clarify the reasoning behind this design choice? Additionally, is there a way to enable case-sensitive validation, or could this be added as an option?

Thanks in advance!

Niraj Raut
Love from 🇮🇳

@rautniraj
Copy link
Contributor Author

 def generate
      length = config.length

      raise RuCaptcha::Errors::Configuration, "length config error, value must in 3..7" unless length.in?(3..7)

      result = RuCaptchaCore.create(length, config.difficulty || 5, config.line, config.noise, config.format)
      [result[0].downcase, result[1].pack("c*")]
    end
def verify_rucaptcha?(_resource = nil, opts = {})
      opts ||= {}

      store_info = RuCaptcha.cache.read(rucaptcha_sesion_key_key)
      # make sure move used key
      RuCaptcha.cache.delete(rucaptcha_sesion_key_key) unless opts[:keep_session]

      # Make sure session exist
      return add_rucaptcha_validation_error if store_info.blank?

      # Make sure not expire
      return add_rucaptcha_validation_error if (Time.now.to_i - store_info[:time]) > RuCaptcha.config.expires_in

      # Make sure parama have captcha
      captcha = (opts[:captcha] || params[:_rucaptcha] || "").downcase.strip
      return add_rucaptcha_validation_error if captcha.blank?

      return add_rucaptcha_validation_error if captcha != store_info[:code]

      true
    end

In both the code i observe you are doing manual downcase, so will it work if i remove this downcase and try to match captcha keeping casesensitive in consideration ?

Before trying out anything i want to know will this break the code in any way based on what design you have followed ?

Thank You
Niraj Raut

@huacnlee
Copy link
Owner

This is by design. Case-In sensitive is used for reduce wrongs.

With 5 Alphabetical characters, it's enough.

@rautniraj
Copy link
Contributor Author

Thank you for your insights.

Our requirement is to maintain a case-sensitive match with a length of four characters, including noise, at a medium difficulty level. However, the current design does not support this.

Can I modify the code to remove the .downcase usage? Will this change be sufficient, or could it cause issues elsewhere?

If this modification works, I will test it in my project. Additionally, I would like to contribute to your project by adding a configuration parameter that allows users to choose between case-sensitive and case-insensitive matching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants