Need help checking if to emails are part of the same domain?

417 views Asked by At

Background information:

I need to make a system that lets users log in by identifying themselves with an email address/password combination. So I'm trying to find a way to check that the login matches something in the database, when the two may be the same address that's typed differently.

So the initial steps for the domain verification are:

  • Convert the entered text to NFC
  • Strip comments with a recursive descent parser
  • split the local part from the domain.
  • run the domain through this:

    nslookup -type=mx $DOMAIN | awk '{ if($2 =="mail" && $3 == "exchanger") { print substr($6, 0, length($6)-1) } else if($2 == "internet" || $2 == "has") { print $1 } }' | sort | uniq'
    

    Which for both me.com and iCloud.com returns:

    mx1.mail.icloud.com
    mx2.mail.icloud.com
    mx3.mail.icloud.com
    mx4.mail.icloud.com
    mx5.mail.icloud.com
    mx6.mail.icloud.com
    

    And gmail.com and googlemail.com both return:

    alt1.gmail-smtp-in.l.google.com
    alt2.gmail-smtp-in.l.google.com
    alt3.gmail-smtp-in.l.google.com
    alt4.gmail-smtp-in.l.google.com
    gmail-smtp-in.l.google.com
    

So I thought I would enter this into a table so that all the gmail servers have id 1, and all the iCloud servers have id 2, etc. in whatever order people try to register them in.

This doesn't work if all the servers are in one varchar unit, because servers could be added or removed at a later date. And it doesn't really work if the servers are all given their own row because there's no way to manipulate them as if they were a single logical unit.

If I get the longest common postfix of each server name would that indicate that these all use one mail server? or would it be possible for that to actually serve two servers separated by subdomains?

1

There are 1 answers

2
Drew On BEST ANSWER

Though I have certainly learned a bit from your question, and I have seen question marks in it at the bottom, I will answer a different question at the bottom here.

But first,

Though you don’t have tags for the likes of php, you do mention the users are logging in, and a mysql database. So I am assuming php and not ssh.

You are not processing incoming emails and ripping thru smtp headers. Rather, [email protected] is typing that and not being cute by typing something else.

--

So the question is,

How do people login with an email address?

Just like every sane system. They enter it like [email protected], password and you do your hashing and proceed.