473,395 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

md5 has for double opt-in: missing something ?

hi all,

I have made a script to register contacts in a database with the double
opt-in system.

Anyway, when looking for some examples, I have found the following
script which uses a md5 hash code to append on the confirm url sent by
email to the registering user.
I tried it but with no results. Don't you think is it missing anything
?
How could it work without storing the hash code for the user in a
database?
To confirm a registration I think the script should look if the access
key matches the one it already knows, shouldn't it ?

Anyway I have no problem to insert into the database the hash code ,
it's just I want to know if I am right to believe the following script
was wrong .

tia

johnny
here's the code

<?
/* Simple email validation by TDavid at http://www.tdscripts.com/
for http://www.php-scripts.com/php_diary/011103.php3
If you use this code then please do not remove this header
*/

$from = $_REQUEST['e_addy'];

// is the $from email address in valid format?
if(eregi("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $from)) {

// create the MD5 hash
$secret_code = 'secret';
$formatted_email = preg_replace("/(-|\@|\.)/", "", $from);
$hashed = md5("$secret_code $formatted_email");

// wait, are we verifying the email?
if($_REQUEST['m'] != "") {
// this is validation routine
if($hashed == $_REQUEST['m']) {
print("Congrats, you have successfully validated your email
address. This is just a test and your email address has <b>not</b> been
saved.");
// add the email to your double opt-in list here
exit;
} else {
print("Sorry, this email does not validate");
}
} else {
// since we aren't validating then it is time to send out
validation mail

$mail_body = "To validate this email click the following
link:\nhttp://www.php-scripts.com/php_diary/example37.php?e_addy=$from&m=$hashed";

mail($from, "Validation Email", $mail_body, "From:
ex*******@php-scripts.com\n");
print("Please check your email <b>$from</b> for the test validation
message");
}
} else {
print("Sorry, this email address: <b>$from</b> doesn't seem to be in
the right format.");
}
?>

Jan 21 '06 #1
2 1833

johnny wrote:
hi all,

I have made a script to register contacts in a database with the double
opt-in system.

Anyway, when looking for some examples, I have found the following
script which uses a md5 hash code to append on the confirm url sent by
email to the registering user.
I tried it but with no results. Don't you think is it missing anything
?
How could it work without storing the hash code for the user in a
database?
To confirm a registration I think the script should look if the access
key matches the one it already knows, shouldn't it ?

Anyway I have no problem to insert into the database the hash code ,
it's just I want to know if I am right to believe the following script
was wrong .

tia

johnny


He doesn't need to store it in the database because the hash is just a
function of the email address and the "secret" which, in your code, is
hardcoded to "secret". In other words, the md5 hash being passed in
the URL is, more or less, is just the has of the email address. So if
they match, the script validates it.

Not all that strong, in my opinion. When I do this sort of thing, I'll
generate a random hash (not based on the email adddress or any other
value) then store it in the database. You can come up with a
reasonably random (hard to guess) hash like this:

$myHash = md5(uniqid(rand(), true));

That could then be stored in the database and compared to the hash
passed in the URL.

Jan 21 '06 #2

"johnny" <mr********@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
hi all,

I have made a script to register contacts in a database with the double
opt-in system.

Anyway, when looking for some examples, I have found the following
script which uses a md5 hash code to append on the confirm url sent by
email to the registering user.
I tried it but with no results. Don't you think is it missing anything
?
How could it work without storing the hash code for the user in a
database?
To confirm a registration I think the script should look if the access
key matches the one it already knows, shouldn't it ?

Anyway I have no problem to insert into the database the hash code ,
it's just I want to know if I am right to believe the following script
was wrong .

tia

johnny
here's the code

<?
/* Simple email validation by TDavid at http://www.tdscripts.com/
for http://www.php-scripts.com/php_diary/011103.php3
If you use this code then please do not remove this header
*/

$from = $_REQUEST['e_addy'];

// is the $from email address in valid format?
if(eregi("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $from)) {

eregi will (because it's POSIX extended) not use the \ as escape but rather
treat them as a \ character. [:alnum:] will work though. \ in a POSIX
character class loses its significance (as I've recently learned). so strip
those out of the character classes. should be
if(eregi("([[:alnum:].-]+)(\@[[:alnum:].-]+\.+)", $from)) {

<?php if(eregi("[[:alnum:]]","z")) echo 1; else echo 0; ?>
1
<?php if(eregi("[\.\-]+","\\")) echo 1; else echo 0; ?>
1
maybe they were looking for preg_match instead.
<?php print preg_match("/[\.]/","\\") . "\n" . preg_match("/[.]/","z"); ?>
0
0
<?php print preg_match("/[\.]/","."); ?>
1

I dunno - loks like the validation thing might work.might need an <a
href=""></a> in the link and send the mail as html email though.

// create the MD5 hash
$secret_code = 'secret';
$formatted_email = preg_replace("/(-|\@|\.)/", "", $from);
$hashed = md5("$secret_code $formatted_email");

// wait, are we verifying the email?
if($_REQUEST['m'] != "") {
// this is validation routine
if($hashed == $_REQUEST['m']) {
print("Congrats, you have successfully validated your email
address. This is just a test and your email address has <b>not</b> been
saved.");
// add the email to your double opt-in list here
exit;
} else {
print("Sorry, this email does not validate");
}
} else {
// since we aren't validating then it is time to send out
validation mail

$mail_body = "To validate this email click the following
link:\nhttp://www.php-scripts.com/php_diary/example37.php?e_addy=$from&m=$hashed";

mail($from, "Validation Email", $mail_body, "From:
ex*******@php-scripts.com\n");
print("Please check your email <b>$from</b> for the test validation
message");
}
} else {
print("Sorry, this email address: <b>$from</b> doesn't seem to be in
the right format.");
}
?>

Feb 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Lionel B | last post by:
Running VC++ 6 under Win2K on i386. I would like to assign a (compile-time) constant that resolves to a quiet NaN (of type double) I can assign a quiet NaN to a *variable* (of type const...
12
by: Sydex | last post by:
When I compile code I get error C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(double)' in this part : double Integration::quad2d(double...
12
by: Alan | last post by:
how to convert double to short ? for example, I want to convert double doubleVal1 = 15000.1; double doubleVal2 = 12000.0; short shortVal; shortVal = doubleVal1 - doubleVal2; I...
10
by: Robert Palma | last post by:
I'm having trouble figuring out how to pass a pointer to a double array (1 dimensional) to a C function. Declaring array as: double xx; Declaring func. int process( double *input ) Calling...
5
by: Markus Kling | last post by:
"double.Parse(double.MaxValue.ToString())" yields the following Exception: Value was either too large or too small for a Double. at System.Number.ParseDouble(String value, NumberStyles options,...
16
by: Martin Jørgensen | last post by:
Hi, Short question: Any particular reason for why I'm getting a warning here: (cast from function call of type int to non-matching type double) xdouble = (double)rand()/(double)RAND_MAX;
2
by: barker7 | last post by:
I use a simple double array plus a variable to store the row size to represent two dimensional data. I need to quickly copy this data to a two dimensional array: double. Currently I iterate...
0
by: =?ISO-8859-1?Q?Tiago_Falc=E3o?= | last post by:
I search on google, msdn,... and i not find no solutions. Any ideia? ---------------------------- C++ Example Source: extern "C" __declspec(dllexport) double * extract(int nrows,int ncols,int...
2
by: Fresh | last post by:
Hi, I met a problem, when I change warning level to 4 and to track warning as error, then a link warning show "warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification" I...
2
by: Genro | last post by:
#include<stdio.h> #include<TX/graphics.h> #include<time.h> // I need help! struct Krug{ double _x; double _y; double _skox; double _skoy; double...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.