Solved

PHP md5 hash a confirmation URL

Posted on 2010-08-20
4
380 Views
Last Modified: 2013-12-13
Hi,

(using PHP and MySQL)

When a unknown user creates an order on my website I want to send an email confirmation to them that will change the order state for that row to 'Active'. I am doing this to make sure that the user entered in their email address correctly(for billing later).

I am unsure of a secure way to do this as I only want the state to be able to change 1 time from "inactive' to 'Active'.

The part that I cannot figure out is how to securely send the url to change the state of the order to the customer.

How would I md5 hash the order id and maybe the page name? instead of looking like this:

http://www.website.com/activate.php?id=3&state=Active

Any suggestions on doing it a better way or help in figuring it out would be gratefully appreciated.

thanks.
0
Comment
Question by:Solutionabc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:JtR
ID: 33489366
if i understand your problem than you just want to make an email confirmation (opt in) for a specific action, right?

you need to save your parameters in the database together with a "randomly" generated hash.
then you send a link on a script with the hash as id to the users email.

when the users runs the script than the script has to read out the action parameters from the database and start the action. and then remove the handle from the database when the action is finished.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 33489400
Make a hash of the current time() and the email address.  Store the current time(), the email address and the md5() hash in your data base, along with a column that is named "verified" and says FALSE.  Send an email to the client with a link to the verification page that looks something like this (note the md5() code of the hash.

Click here to verify your order:
http://example.com/verify.php?q=6eea9b7ef19179a06954edd0f6c05ceb

In the "verify.php" script, find the value in $_GET["q"] and use it to query the data base for a SELECT match on the md5() hash.  If it is not found, issue an error message.  If it is found, change the column named "verified" to say TRUE.  And send another email to the client saying "Thank You!"

As you code this, remember that email addresses are not case-sensitive, but md5() hashes treat the input as case-sensitive.  So you might want to use strtoupper() on the inputs to the md5() function calls.
0
 
LVL 3

Expert Comment

by:JtR
ID: 33489492
If you do it like Ray Paseur suggest then don't forget to clean/validate the $_SET['q'] before writing it to the MySQL query! (risk of SQL INJECTION).

i would not save the email, i would only save the Hash and the identifiers for the action that you want to do when the address is verified. you also should add a colum for a timeout so that the login handle "expires" after a while.

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 33491266
If you do not save the email, you won't be able to send a "Thank You" message.  I cannot think of any application design that would deliberately lose a piece of data that is this important.  The idea about having a date for expiring the offer is a good one.  You could even have a cron job that runs once a day and looks for orders that are nearing expiration.  You could send a reminder message ("Only three more days...") to those clients.

I suppose it should go without saying that any script that takes data from the URL ($_GET["q"] is the correct variable in the example, not $_SET) needs to filter that data.  In the case of an expected md5() string, you can see that it consists of letters and numbers only, is 32 bytes long.  These are easy things to test for, and a string that fails these tests can simply be discarded.  For general advice and assistance in cleaning up external input, the PHP filter functions are most valuable.
http://us2.php.net/manual/en/filter.filters.php

Best regards, ~Ray
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to count occurrences of each item in an array.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question