This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

oscman

  • ****
  • 227 posts
Allow only specific email providers
« on: December 23, 2019, 12:32:42 PM »
Hello, i have this function so people can register only with gmail and hotmail, when i try to register it works gr8 but i still see spambots registering under different email domains and bypass this code, any idea how they do it?

Code: [Select]
function cust_restrict_mail_providers() {

    $authorized_providers = array(
        'gmail.com',
        'hotmail.com'
    );
    $current_provider = preg_replace('/^.*@(.*)$/i', '$1', Params::getParam('s_email'));

    if (!in_array($current_provider, $authorized_providers)) {
        osc_add_flash_error_message( _m('Your current email is not allowed'));
        osc_redirect_to(osc_register_account_url());
    }
}

osc_add_hook('before_user_register', 'cust_restrict_mail_providers');

*

MB Themes

Re: Allow only specific email providers
« Reply #1 on: December 23, 2019, 02:19:21 PM »
Code looks OK, but try to put:
Code: [Select]
exit;
after line:
Code: [Select]
osc_redirect_to(osc_register_account_url());
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

oscman

  • ****
  • 227 posts
Re: Allow only specific email providers
« Reply #2 on: December 23, 2019, 09:14:51 PM »
Thanks will see if it makes change

Re: Allow only specific email providers
« Reply #3 on: April 20, 2022, 07:52:26 AM »
Hello There ,

I also want to restrict users for registration, where i have to paste this code (in which file ).. I want to allow only some popular email server like gmail.com, live.com and more.. Because too many fake registration in my website.   

I have tried to put this code in user registration php file but not working . Please help me to solve the issue.   

<?php
function cust_restrict_mail_providers() {

    $authorized_providers = array(
        'hotmail.com',
        'mail.live.com',
        'live.com',
        'gmail.com'
    );
    $current_provider = preg_replace('/^.*@(.*)$/i', '$1', Params::getParam('s_email'));

    if (in_array($current_provider, $authorized_providers)) {
        osc_add_flash_error_message( _m('Accounts not allowed'));
        osc_redirect_to(osc_register_account_url());
      exit;
    }
}

osc_add_hook('before_user_register', 'cust_restrict_mail_providers');
?>


Thanks
« Last Edit: April 20, 2022, 08:42:50 AM by Sanjay Srivastava »

Re: Allow only specific email providers
« Reply #4 on: April 20, 2022, 07:05:33 PM »

Please reply

Code looks OK, but try to put:
Code: [Select]
exit;
after line:
Code: [Select]
osc_redirect_to(osc_register_account_url());

*

MB Themes

Re: Allow only specific email providers
« Reply #5 on: April 20, 2022, 08:03:01 PM »
You can place it into functions.php of theme
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Re: Allow only specific email providers
« Reply #6 on: April 20, 2022, 08:13:28 PM »
Thanks for Reply.

I have pasted this code into functions.php but still I am able to register fake account. [email protected]

<?php
function cust_restrict_mail_providers() {

    $authorized_providers = array(
        'hotmail.com',
        'mail.live.com',
        'live.com',
        'gmail.com'
    );
    $current_provider = preg_replace('/^.*@(.*)$/i', '$1', Params::getParam('s_email'));

    if (in_array($current_provider, $authorized_providers)) {
        osc_add_flash_error_message( _m('Accounts not allowed'));
        osc_redirect_to(osc_register_account_url());
      exit;
    }
}

osc_add_hook('before_user_register', 'cust_restrict_mail_providers');
?>


You can place it into functions.php of theme

*

MB Themes

Re: Allow only specific email providers
« Reply #7 on: April 20, 2022, 08:20:30 PM »
I would double check if email field on register page has nane s_email and then I think condition should be !in_array(...
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Re: Allow only specific email providers
« Reply #8 on: April 20, 2022, 09:11:01 PM »
Thanks for your Reply. Now its working.  :) :)

I would double check if email field on register page has nane s_email and then I think condition should be !in_array(...

Marked as best answer by frosticek on April 21, 2022, 10:45:36 AM
*

MB Themes

Re: Allow only specific email providers
« Reply #9 on: April 21, 2022, 10:45:26 AM »
I would just summarize final code.

Code: [Select]
// restrict particular email domains
function cust_restrict_mail_providers1() {
    $authorized_providers = array(
        'hotmail.com',
        'mail.live.com',
        'live.com',
        'gmail.com'
    );

    $current_provider = preg_replace('/^.*@(.*)$/i', '$1', Params::getParam('s_email'));

    if (in_array($current_provider, $authorized_providers)) {
        osc_add_flash_error_message(_m('Email domain is blocked'));
        osc_redirect_to(osc_register_account_url());
      exit;
    }
}

osc_add_hook('before_user_register', 'cust_restrict_mail_providers1');

// only allow particular email domains
function cust_restrict_mail_providers2() {
    $authorized_providers = array(
        'hotmail.com',
        'mail.live.com',
        'live.com',
        'gmail.com'
    );

    $current_provider = preg_replace('/^.*@(.*)$/i', '$1', Params::getParam('s_email'));

    if (!in_array($current_provider, $authorized_providers)) {
        osc_add_flash_error_message(_m('Email domain is not allowed'));
        osc_redirect_to(osc_register_account_url());
      exit;
    }
}

osc_add_hook('before_user_register', 'cust_restrict_mail_providers2');

  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Re: Allow only specific email providers
« Reply #10 on: April 21, 2022, 11:11:46 AM »
Thanks for reply.. but its already working