News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Restrict registration to certain email domains

Started by picture, October 20, 2006, 05:09:44 AM

Previous topic - Next topic

picture

Hey,
I have come across many posts on this topic, and this the only one with any real conclusion:
http://www.simplemachines.org/community/index.php?topic=77504.0

I'm just wondering if there is anything else to contribute besides the above. How can forum admins restrict registration to users who have a certain email domain such as *@domain.com? The above post's solution apparently still allows users to sign in after registering and change their email address to something else. Is that as good as it gets right now? Also, did anyone actually try the above method and have good results? It seems to be a dead post...

Thanks.

Oldiesmann

That method will work for preventing people from registering from other email domains. You will need to make a similar change to Profile.php to prevent them from changing their email to something other than *@domain.com (* = wildcard ;)):

Sources/Profile.php

Find
if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]+@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', stripslashes($_POST['emailAddress'])) == 0)
$post_errors[] = 'bad_email';


Replace
if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]+@domain\.com$~', stripslashes($_POST['emailAddress'])) == 0)
$post_errors[] = 'bad_email';
Michael Eshom
Christian Metal Fans

picture

thanks Oldies! Gonna save this and try it out.
;)

picture

Okay well I'm finally ready to implement this email restriction. However, the older topic I shared earlier seems to have outdated instructions. Oldies, you explained how to prevent profiles from being changed to other email domains, but this older post tried to address forcing a certain domain at the time of registration.

Quote from: Thantos on June 09, 2006, 02:23:08 AM
Not 100% sure as I haven't tried it out but try opening Register.php and find
[code]        if (empty($_POST['email']) || preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]+@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', stripslashes($_POST['email'])) == 0)


and replace it with
        if (empty($_POST['email']) || preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]+@name\.gov$~', stripslashes($_POST['email'])) == 0)
[/code]

Of course that only works for one domain.  It also won't prevent them from changing the email to another domain later.


However, I can't find this code anywhere in Register.php in the RC3 SMF build, so I'm wondering if there is a newer solution for the current coding...sorry...I am not a coder! I found this code, but I'm not sure if its the right code to change, or what I should change it to:

if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', stripslashes($_POST['new_email'])) == 0)
fatal_error(sprintf($txt[500], htmlspecialchars($_POST['new_email'])), false);


Thanks for all the help!


lt_wentoncha

Hi all,

Did the reg expression change in 1.1RC3? I don't see the one listed above in Register.php; all I see is

if (isset($_POST['MSN']) && preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['MSN']) != 0)
$profile_strings[] = 'MSN';


Is that the one? Thanks.


picture

Allright everyone who has been waiting, we finally figured it out with the help of lt_wentoncha!!!

Keep in mind, this solution works for SMF 1.1 RC3 but probably not too many earlier versions. This might not be a very kosher way of modifying the code, so remember, change it at your own risk!

To limit user registration to usernames@*.domain.com use the following expression:

^[^@]+@(.*\.)?domain\.com$

@ around line 635 in /Sources/Sub-Members.php. To change the resultant error code, go to /Themes/.../Login.english.php and change $txt[501].

Good luck ;)

Advertisement: