Hi All,
Kindly i need to ask how to can create a custom authentication logic with WP Cerber , as the user own two different usernames on same account and same password , and can login with any one of them
i add below code & working perfect but without WP cerber , if i enable WP Cerber code not working.
// Authenticate user with either primary or second username
function custom_authenticate_user($user, $username, $password) {
// If a WP_Error is returned, continue
if (is_a($user, 'WP_Error')) {
global $wpdb;
// Check if the username exists in the second_username field
$user_id = $wpdb->get_var($wpdb->prepare(
"SELECT ID FROM $wpdb->users WHERE second_username = %s",
$username
));
if ($user_id) {
$user_info = get_userdata($user_id);
$username = $user_info->user_login;
}
}
// Re-attempt authentication with the updated username
remove_filter('authenticate', 'custom_authenticate_user', 30, 3);
$user = wp_authenticate_username_password(null, $username, $password);
add_filter('authenticate', 'custom_authenticate_user', 30, 3);
return $user;
}
add_filter('authenticate', 'custom_authenticate_user', 30, 3);