Solved

Website Email Validation

Posted on 2007-03-17
8
210 Views
Last Modified: 2012-05-05
Hi,

I am looking to implement quite a common bit of functionality on my website. I have a login page where users provide their login details and are then signed up to become members. Unfortunately the website is getting invalid website addresses used to create the accounts. Ive seen on some websites that when you sign up they send an email to the specified email address with a link, which when clicked validates the address and finalises the account creation. This is what I would like to implement on my website account setup.

I am using PHP and MySQL on the website.

Thanks in advance for any advice posted.

0
Comment
Question by:Benjamin297
8 Comments
 
LVL 28

Expert Comment

by:gamebits
ID: 18739899
vSignup 2.5 available here offer this feature as well as many others, free to use, excellent script, if you don't want to use this script you can always have a look at the code and see how it is implemented.

http://www.beanbug.net/vScripts.php
0
 
LVL 9

Accepted Solution

by:
under_dog earned 125 total points
ID: 18739904
What you want to do is:

1/ When the user signs up generate a random 10-15 digit code and save it to your users table. Make sure it's unique to that user.

2/ Have a field in your users table called "validated" or something similar. Make it boolean.

3/ When the user signs up send them a link to your "validation" page which will include in the URL string the code you generated in step 1.

4/ When they arrive at the validation page look up the code they have arrived with in your database and update the "validated" field to true.

5/ On the login page when you check the username and password, also check the "validated" field.

Extra:

- You can also include a datetime field for when they initially signup and regularly delete all the rows where they haven't validated in say 3 days to keep your db nice and clean.
0
 
LVL 4

Assisted Solution

by:HTorres
HTorres earned 125 total points
ID: 18746332
you want code samples ?
0
 
LVL 1

Author Comment

by:Benjamin297
ID: 18751098
If youve got them then that would be great!
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Expert Comment

by:HTorres
ID: 18751319


first, the registration part
<?
  // check if the user already exists
  $sql = "select * from users where username = '" . $usuario . "' limit 1; " ;
  $result = mysql_query($sql, $dbh );
  $numrows = mysql_numrows($result);
 
  if ($numrows >= 1) { $reason=$reason . "<li> The username you specified already exists, please choose another one<br>" }
  if ($field3=="") { $reason=$reason . "<li> Field 3 cannot be empty"; }
  //additional validation, as... email syntax, another required fields
 
  if ($reason!="")
    {
      // Says reeason(s)
      echo $reason;
    } echo {
      // it does not exist, and the rest of info its ok.

      #$vocales="aeiou";
      #$consonantes="bcdfghjklmnpqrstvwxyz";
      $numeros="0123456789";
     
      $randomsec="";
     
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
      // adds one number
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
      // adds one number
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
      // adds one number
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
      // adds one number
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
      // adds one number
      $randomsec=$randomsec . substr($numeros, rand(0,9),1);
     
      // insert
      $sql = "INSERT INTO users ( username,   validated, randomsec,   field3, field4, field5, field6, field7 ) " .  
                       " VALUES ('$username', '0',      '$randomsec', '0',    '0',    '0',    '0',    '0',   ) ";
      $result = mysql_query($sql, $dbh );

      //notify                    
      $confirmacion="
     
      YourSite.com
      Your slogan
     
      We are glad you become a new member!!!
     
      Please confirm your registration using this link
      http://www.yoursite.com/confirmations.php?userid=" . urlencode($username) . "&rs=" . md5($randomsec) . "
     
      Thank you again and have a nice day.
     
      YourSite.com
      Member Registration
     
      Powered by YourCompany.com" ;
     
      mail($useremail, "Registration", $confirmacion ,
      "From: do-not-reply@yoursite.com\r\n" .                        
      "Reply-To: do-not-reply@yoursite.com\r\n" .
      "X-Mailer: PHP/" . phpversion() . "\r\n"  );

      echo "An email has been sent to the mail address " . $useremail . " please confirm your registration.";      

    }
   
?>
0
 
LVL 4

Expert Comment

by:HTorres
ID: 18751423
second, the confirmations.php file

<?
// creates db connection
....

if ($userid=="" or $rs=="")
  {
    echo " please use the link provided in the mail sent to you ... ";
  } else {

    // queries
    $userid=urldecode($userid);
    $sql = "select * from users where username = '" . $userid . "' limit 1; " ;
    $result = mysql_query($sql, $dbh );
    $numrows = mysql_numrows($result);
   
    $row=mysql_fetch_assoc($result)
    if ( md5($row[randomsec])==$rs )
      {
        // saves it
        $sql = "update users set validated='1' where `username`='" . $userid . "' ; ";
        $result = mysql_query($sql, $dbh );
        echo "thank you, welcome... go here and there, and here it is al the extra blah blah blah";
      } else {
        echo " please use the link provided in the mail sent to you ... ";
      }
  }
?>
0
 
LVL 4

Expert Comment

by:HTorres
ID: 18751493
you can get rid of the line
 $numrows = mysql_numrows($result);
in the confirmations.php file.

no need of that.

hope this helps you.

this can be easily override by using a 2prong account.

the nicest way to confirm registration is one i saw.  They charge you $0.01 and in your account statement they provide a number.  since noone can fake an account statement, its 100% sure, the only disadvantage is that this last procedure takes about 2~4 days.
0
 
LVL 4

Expert Comment

by:HTorres
ID: 18751532
works even better if you use something like this in your form

<tr>
<td align=right> eMail </td>
<td> <input type=text name=email1>@<input type=text name=email2> </td>
</tr>
and a confirmation field
<tr>
<td align=right> confirm </td>
<td> <input type=text name=email1a>@<input type=text name=email2a> </td>
</tr>
and confirmation code before your insert secuence

if ($email1!=$email1a or $email2!=$email2a or $email1=="" or $email2=="" or $email1a=="" or $email2a=="" )
{
$reason=$reason . "<li> Please check your email";
}

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now