Jump to content

Best Method For User Authentication?


justlukeyou

Recommended Posts

Hi,

 

I have spent the last few months creating a membership script. It now appears to be coming together however there is one aspect which I am unsure on how to proceed which I am hoping someone will be able to advise on.

 

When someone adds their email address they receive an email confirmation. However I am unsure on how pass onto the DB that the account has been created. I am planning to add a link to the email which when clicked inserts the letter Y (Yes) into a column for 'Activated'. Alternatively I am considering trying to insert a matching number as a safer system however this sounds quite complex in comparison to inserting a simple Y.

 

When someone attempts to log in I will read if the Y is inserted and then log the user in. If the Y is not inserted I will ask them to re-submit their email address.

 

Does anyone have any views on the safe method of authenticating a user registration?

Link to comment
Share on other sites

When you create the user:

 

// add user to database
// "INSERT INTO users ( id, username, ..., activated ) VALUES ( NULL, ..., 0 )";
// generate an identifiable hash
// from some include file (without the comment (/* ... */))
/*
function getActivationId($username) {
return md5($username . 's0m3r4nd0m54lt');
}
*/
$link = 'http://'. $_SERVER['SERVER_NAME'] .'/activate.php?user='. $username .'&activation_id='. getActivationId($username);
// send link in email

 

// activate.php
if ( $_GET['activation_id'] == getActivationId($_GET['username']) ) {
// query "UPDATE users SET activated = 1 WHERE username = :username"
} else {
echo 'Incorrect activation ID';
}

Edited by Andy-H
Link to comment
Share on other sites

Hi,

 

This is what I have so far. I cant get the link to work to begin which is odd.

 

Do links in emails work differently?

 

if(!$errors){
  $query = "INSERT INTO users (firstname, surname, email, password, date_registered) VALUES ('" . $firstname . "', '" . $surname . "', '" . mysql_real_escape_string($registerEmail) . "', MD5('" . mysql_real_escape_string($registerPassword) . "'), NOW())";

 $result = mysql_query($query) or die(mysql_error()); // remove the or die(mysql_error()) code after you resolve the error
 if($result){
	  $success['register'] = 'Thank you for registering. You will soon receive a confirmation email.  Please click the confirmation link.';




	  $message = '
<html>
<body>
<a href="www.test.com/test/activation.php?userid=Y">Click Here</a> to activate your account.

</body>
</html>
';


	  mail(mysql_real_escape_string($registerEmail), '.com Confirmation', $message, 'From: info@all.com' . "\r\n".'MIME-Version: 1.0' . "\r\n".'Content-type: text/html; charset=iso-8859-1' . "\r\n");

  }else{
	  $errors['register'] = 'There was a problem registering you. Please check your details and try again.';
 }
} 
		   }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.