LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-29-2004, 01:35 PM   #1
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Rep: Reputation: 30
Simple PHP question


I am coding a registration page for my brother's web site.

A user submits registration details, and when he clicks submit an email is sent to him so he can verify his registration.

In the body of the email there is a link for the user to click to verify the registration.

What is the most common way of handling this situation? Right not I just have a link which passes the parameters username and password, where the password is encrypted. However, these details I feel should not be visible or obvious.

I'm wondering if there is a better way?

Thanks for any help!
 
Old 02-29-2004, 02:15 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You could generate a random 20 character string to be inlcluded in the e-mail and store that along with the users details on the server.
 
Old 02-29-2004, 02:18 PM   #3
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
That's funny, I just thought of doing something like that.
My only reservation would be that perhaps more than one user gets the same random string? I know this would be highly unlikely, but is it possible?

Thanks for the response.
 
Old 02-29-2004, 02:21 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You don't even need to use a random string, just store the details in a database and use an auto incremented user id field.
 
Old 02-29-2004, 02:22 PM   #5
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
And for security purposes you think something like this would be fine?
 
Old 02-29-2004, 02:24 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I'm not quite what part of the security you are worried about. I assume your brother has to enter the admin username and password to confirm the details?
 
Old 02-29-2004, 02:37 PM   #7
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
Sorry, I should have been more clear.

When the user clicks the link in the email, it takes him to a page which shows a message that his account is activated.
This page will also contain the PHP code which activates his username in the database, by simply changing a value in one of the fields.

Thanks
 
Old 02-29-2004, 02:40 PM   #8
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Then why not use a combination of a random string (could be the result of a "crypt" on their e-mail addy) and their user id.
 
Old 02-29-2004, 02:46 PM   #9
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
Ok! Now we're getting somewhere.

This is what I have already done actually. So the details of the link in the email are encrypted. For example:

"Click here" is the link:

www.somesite.com/verify.php?-0193n13gf-9ng0pdld

where the crypted part is really:
"user=name&pass=somepass"

But on the page verify.php,
if I simply echo $user; and echo $pass

I get nothing!
 
Old 02-29-2004, 03:40 PM   #10
guardian653
Member
 
Registered: Oct 2003
Distribution: Gentoo
Posts: 79

Rep: Reputation: 15
Well, I'm not sure if you already know this, but in order to get a URI argument you have to use $_GET (e.g. $_GET['user']) but since you encrypted the entire query you'll have to do this manually. I don't know how you used the crypt() function, but maybe something like this will help

Code:
$userinfo = $_SERVER['QUERY_STRING'];  // Replace here code to decrypt var
$parsedata = preg_split("/(user|&password)=/i", $userinfo, -1, PREG_SPLIT_NO_EMPTY);
$user = ereg_replace("[^A-Za-z0-9]", null, $parsedata[0]);
$pass = $parsedata[1];
I'm not sure if this code will be safe enough for you. It does split the query based on literals, but it is case-insensitive. It also checks the username for invaild characters (only letters and numbers are allowed).

Examples
Request: /test2.php?user=d&avid&password=12&345
Output:
query = user=d&avid&password=12&345
user = david
password = 12&345

Request: /test2.php?user=david+4&password=12&345&&&password=123&^4
query = user=david+4&password=12&345&&&password=123&^4
user = david
password = 12&345&&


Hope this points you in the right direction!

Last edited by guardian653; 06-26-2009 at 10:25 PM.
 
Old 02-29-2004, 03:55 PM   #11
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
Is this what you mean:

$user = $_SERVER['user'];

if "user" is the argument name in the URI?
 
Old 02-29-2004, 04:03 PM   #12
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
I suppose I'm also going to have problems using crypt() since it seems only to be one way.
 
Old 02-29-2004, 04:09 PM   #13
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I have no idea why you want to decrypt it? You already have the unencrypted version on the server.
 
Old 02-29-2004, 04:35 PM   #14
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
Well then why won't something like this work?

<?php
echo "Username: $user";
echo "Password: " . $pass";
?>

If I use:
$user = $_SERVER['QUERY_STRING'];

it simply returns the entire crypted string which is really:

user=$user&pass=$pass

But how would I extract $user and $pass from that?

Sorry if these are dumb questions, but I'm really quite new to this still.

Thanks
 
Old 02-29-2004, 05:57 PM   #15
haobaba1
Member
 
Registered: Jul 2003
Location: VA Tech
Distribution: Mandrake 9.1
Posts: 73

Rep: Reputation: 15
Re: Simple PHP question

Quote:
Originally posted by jacksmash
I am coding a registration page for my brother's web site.

A user submits registration details, and when he clicks submit an email is sent to him so he can verify his registration.

In the body of the email there is a link for the user to click to verify the registration.

What is the most common way of handling this situation? Right not I just have a link which passes the parameters username and password, where the password is encrypted. However, these details I feel should not be visible or obvious.

I'm wondering if there is a better way?

Thanks for any help!
I did this before by getting the time of the registration and using the long value of the time as a temporary registration ID.

You can hash the users password and store it in a temporary table along with the users other information and then just move it when the email address has been verified.

Last edited by haobaba1; 02-29-2004 at 06:01 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
simple apache - php question davespink Linux - Newbie 4 12-28-2005 04:47 PM
Simple PHP Question newuser455 Programming 9 08-28-2005 11:58 PM
simple php question jfall Programming 1 05-03-2005 02:57 PM
Simple PHP Question jacksmash Programming 21 01-04-2004 08:31 PM
simple question...where is php.ini taran Linux - Software 3 08-25-2003 01:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration