Hello, is anyone using antibot challenge that does not rely on recaptcha or similar spyware?
I have tried to ask HivePress AI and Lumo, but both gives non working code which does not report error and avoids registration entirely.
Sample **non-**working code:
// 1. Add math challenge to registration form
add_filter(
'hivepress/v1/forms/user_register',
function( $form ) {
// Generate new random numbers each time form renders
$num1 = rand( 5, 15 );
$num2 = rand( 5, 15 );
// Store answer in transient with UUID key
$challenge_id = wp_generate_uuid4();
set_transient( 'hp_math_answer_' . $challenge_id, $num1 + $num2, HOUR_IN_SECONDS );
$form['fields']['math_challenge_id'] = [
'type' => 'hidden',
'value' => $challenge_id,
];
$form['fields']['math_challenge'] = [
'label' => sprintf( 'What is %d + %d?', $num1, $num2 ),
'type' => 'text',
'required' => true,
'_order' => 100,
];
return $form;
},
1000
);
// 2. Validate answer
add_filter(
'hivepress/v1/forms/user_register/errors',
function( $errors, $form ) {
if ( isset( $_POST['math_challenge'], $_POST['math_challenge_id'] ) ) {
$challenge_id = sanitize_text_field( $_POST['math_challenge_id'] );
$user_answer = (int) $_POST['math_challenge'];
$correct_answer = get_transient( 'hp_math_answer_' . $challenge_id );
if ( false === $correct_answer ) {
$errors[] = 'Math challenge expired. Please refresh the page.';
} elseif ( $user_answer !== $correct_answer ) {
$errors[] = 'Incorrect answer. Please try again.';
} else {
// Success - delete transient
delete_transient( 'hp_math_answer_' . $challenge_id );
}
}
return $errors;
},
1000,
2
);
Working code, BUT reliant on a third party service and WP plugin (unwanted in this case) is:
// Add hCaptcha to user register form
add_filter(
'hivepress/v1/forms/user_register',
function( $form ) {
$form['footer'] = '<div id="my-hcaptcha-box">' . do_shortcode('[hcaptcha]') . '</div>' . hivepress()->helper->get_array_value( $form, 'footer' );
return $form;
},
100
);
// Throw error if hCaptcha is missing
add_filter(
'hivepress/v1/forms/user_register/errors',
function( $errors, $form ) {
$result = \HCaptcha\Helpers\API::verify_request();
if ( null !== $result ) {
$errors[] = 'Please solve the hCaptcha.';
}
return $errors;
},
100,
2
);
(above hcaptcha code is from this tutorial)
if you do not have working solution and looking for one, are you able to tweak some of these codes to work? Yes, i know this is a weak protection, but i am unable to come up with better as a non-developer. But the idea may be using Javascript in the challenge or some drag/drop action.