I have a user account 'member center' that shows all of a customer's subscriptions and memberships that they have with my company. This is at https://secure.example1.com/membercenter/.
I have another site which is the actual member site. This is at http://www.example2.com/. ( each site on a different domain, though it is the same dedicated server.
I want to provide easy login to the membership site, without including the user's username and password in the link.
So what I've come up with is this:
When the user clicks the 'Login' link for their membership, I create an md5 hash of their userid + unix timestamp, and add that into a database table along with their userid and the timestamp.
I then redirect to http://www.example2.com/login?hash=(the hash).
The login script on example2 takes the hash and looks it up in that same table. If the hash is present, I retrieve their username and password from the customer database using the userid stored with the hash, and pass it into the site's pre-existing login function, and they get logged in.
When this hash login script runs, it first deletes any rows older than 5 minutes, then checks for the hash value passed. If it finds the hash, it logs the user in, and then deletes the hash that was used from the table. This means that there will never be any hashes in the table older than 5 minutes. The only time there would (should) be any hashes left over in the table is if the user somehow doesnt make it from secure.example1.com to www.example2.com after clicking the link ( say, internet goes down at just the right second, dns problems resolving example2.com, etc ). The 5 minute expiration means they can sit there and reload the redirected URL until they get in, or until 5 minutes have gone by.
When the user is redirected, they do see the hash value.
Every time the login link is clicked from secure.example2.com, a new hash value is calculated and stored.
My question is... am I missing something obvious? How would you break or hack this? Did I just create a gaping security hole in my site(s)?
Thanks SO Hive Mind!
EDIT: This is in addition to the normal model of coming to www.example2.com and logging in with a form using your username / password.
EDIT2: Response to tobyhede re: sniffing the hash. The attacker would have to also stop the user from reaching the login script on www.example2.com as the hash is deleted once used. If they were able to stop that, they would then also have to use the hash within five minutes or it would be automatically deleted.
EDIT3: Re: Attacker generating their own hashes: A hacker would have to insert those hashes into the database AND include a valid userid ( no users know their userid ). How would they do that? Since the hash is used only once and then deleted immediately, I'm not convinced any of the below attacks would work.