
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Humanizer is a very simple CAPTCHA method. It has a localized YAML file with questions and answers which is used to validate that the user is an actual human. Any model that includes ActiveModel::Validations should work. Our aim is to be database and mapper agnostic, so if it doesn't work for you, open an issue. Humanizer works with Rails 3 and 4.
Add humanizer
to your Gemfile:
gem 'humanizer'
Bundle and run the generator in terminal:
bundle
rails g humanizer
rails g humanizer --all-locales
rails g humanizer --show-locales
rails g humanizer en fi de
class User < ActiveRecord::Base
include Humanizer
require_human_on :create
end
<%= f.label :humanizer_answer, @model.humanizer_question %>
<%= f.text_field :humanizer_answer %>
<%= f.hidden_field :humanizer_question_id %>
If you are using attr_accessible, remember to whitelist :humanizer_answer
and :humanizer_question_id
.
If you are using strong_parameters, remember to permit :humanizer_answer
and :humanizer_question_id
.
Alternatively, you many use the built in HumanizerHelper class instead of using your own model (useful for something like a contact form if you don't have a model/class for this). Behavior is the same including Humanizer
on a model, but all setters are available as optional arguments when initializing a HumanizerHelper instance.
@humanizer_helper = HumanizerHelper.new
<%= label_tag :humanizer_answer, @humanizer_helper.humanizer_question %>
<%= text_field_tag :humanizer_answer %>
<%= hidden_field_tag :humanizer_question_id, @humanizer_helper.humanizer_question_id %>
humanizer_helper = HumanizerHelper.new(humanizer_answer: params[:humanizer_answer], humanizer_question_id: params[:humanizer_question_id])
if humanizer_helper.humanizer_correct_answer?
do_stuff
end
A HumanizerHelper instance provides an additional get_correct_humanizer_answer
method to make testing easier. Example:
question_id = find('#humanizer_question_id', visible: false).value #gets humanizer question id from example form above
humanizer_helper = HumanizerHelper.new(humanizer_question_id: question_id)
fill_in 'humanizer_answer', with: humanizer_helper.get_correct_humanizer_answer #fills in answer field from example above with the correct answer
Default translations can be found in config/locales/
You might want to add/change question and answer pairs. This can be easily done by adding/modifying entries in locales file.
You might want to skip the humanizer validations on your tests or rails console.
You can just have a simple attribute on your model and use it to bypass the validation. Here's an example:
attr_accessor :bypass_humanizer
require_human_on :create, :unless => :bypass_humanizer
Now when bypass_humanizer is true, validation will be skipped.
In case you want to give your users the option to change the question, there's a #change_humanizer_question method to help you.
To make sure the current question doesn't get asked again, you can pass the current question id to the method. For example:
@user.change_humanizer_question(params[:user][:humanizer_question_id])
Humanizer is licensed under the MIT License, for more details see the LICENSE file.
FAQs
Unknown package
We found that humanizer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.