Forum Moderators: coopster

Message Too Old, No Replies

Authentication with IP and Password

How to restrict access with dynamic IP address and passwords

         

percy05

6:29 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



Hi, here goes: I want to restrict the access to certain paid parts of my site for Unique registered users. It should be not only with username and password, because they can be shared among many users. I had thought to use the IP address of a registered user as a way to limit using the same password and username by many people, that is, that the system recognize the "true" user comparing the password and username with his/her IP address. I know that I can store the original IP address whith a user has been registered and I guess I can compare it with his/her password/username for giving login. The problem is that the IP are dynamic, so they can change every time the user connects to Internet and the authentication process would have problems. I am new in PHP and have thought in using Remote_Addr for recognize IP, but I don't know how more to do. Do you know a good solution for this or have another good ideas, please? Thanks a lot.

mcibor

9:03 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the IPs are dynamic there isn't a way you can connect them to the one and only user. But tell me one thing... why can't you put unique usernames, as it is done with e.g. email?

Among the users this isn't a problem at all, and takes a heck of a burden from you. BTW if this is a company people still would take over their colleagues seat and write something in their name, so don't worry.

I would really stick to the idea of the distinct user names.

Best regards
Michal Cibor

But if you really want, the user's IP is in $_SERVER['REMOTE_ADDR'] - add that to user table in your db (where you store username and hash of a password)

percy05

3:58 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Thanks for the reply and ideas, but if I use unique usernames as restriction, many people can use this unique one to have access. That is, one person subscribe (and pay) to have access to paid contents of my site and he/she share this username and password with ten or 100 people who do not need to subscribe (and pay) because they have the right username and password to login. People do not share username/password of emails because they don't want that other people could view their personal affairs in their email inbox, but this is not the case of paid information/content, in my case education information, because many students and people would like to share it. That's why I had thought in associating IP addresses with login, but maybe there are other useful association and ideas. Thanks a lot.

ironik

4:26 am on Apr 28, 2005 (gmt 0)

10+ Year Member



IP addresses can change (legitimately) often, so it's not going to be an accurate way of restricting access. In the case of many users they are not assigned a static IP address when they log into their ISP, they are assigned something from the ISP's IP range.

If you want to prevent users from handing out usernames and passwords you'll have to put something a little more dynamic in place. A suggestion would be to have a regularly changing 'token' that is supplied to the user via email. In order to login they must supply their username and their token. If it changes each week, and they hand out their username and token, then that will only be good for a little while before a new one is generated.

Another idea might be that the user is forced to enter personal information periodically. That will probably discourage most users from handing out login details as they'd have to supply their personal details as well.

One more idea... Use the user's email as the login name. If they are going to hand it out publicly then there they will likely receive a flood of spam as well.

It's likely to annoy users if it's too hard a system to use, but if there is a need to be concientious about access then a continuously changing login information, challenging the user or forcing the use of personal information in a login might be the way to go.

percy05

6:44 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



Thanks, they are good ideas, but is there not really a programming way to control access with dynamic ip's or something like? Thanks a lot

mcibor

8:14 pm on Apr 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There may be a way - with assigning cookie, eg after user authentification by email. I mean: send user an email with a link, then while he's visiting the page set a cookie on his pc.

However I'm a student myself, and I know that if you put some restricted access, then still most of the people might take what you have there - simply save and then distribute.

You cannot make the page completely pirate proof.

Best regards
Michal Cibor

jatar_k

8:34 pm on Apr 29, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You cant do much with IP really, what about someone who paid when they were at home and then wants to access the content they paid for from another copmputer, different ip.

What about users on a network, their external ip will all be the same anyway.

what about AOL, there are far more users than there are ips.

even high speed users, sure their ips seldom change, but they still change.

auth by ip is just a bad idea, you will need other criteria and then unfortunately if people share their personal information then they share their information, not much you can do.

One thing ip is good for is to make sure a user doesn't switch ip's on an active session, if so, force them to re auth.

percy05

9:36 pm on Apr 29, 2005 (gmt 0)

10+ Year Member



Thanks Michal, a good idea the one with the cookie. I know that certainly a page will never totally pirate proof and I cannot avoid that users share downloaded information, but I think it is possible to avoid that users share their way to login in the page, via ip's, passwords or cookies restrictions. I know that maybe you don't have enough time to explain, but could you please explain it a bit more? How can I do it? Thanks a lot. -Percy

And thanks Jatar K. What you say it's true, because ip's restriction has many limitations and definetely could give some annoys to users, but what other ideas are possible? The MCibor's one is good and maybe there are a bit more. If people wants to share info after got it, nothing I can do, but what I would like -if it is possible with programming- is to avoid that the same user can revel his/her login user/password to many people with and continue normally login, he/she and the other people. Thanks for your ideas, and thanks a lot.-Percy

percy05

6:39 pm on Apr 30, 2005 (gmt 0)

10+ Year Member



And is it possible to do with cookies? - Thanks a lot.

GaryK

6:47 pm on Apr 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One thing ip is good for is to make sure a user doesn't switch ip's on an active session, if so, force them to re auth.
How would that affect AOL users where one page can be requested by multiple IP Addresses?

percy05

7:02 pm on Apr 30, 2005 (gmt 0)

10+ Year Member



Good question. I don't know how. BUt is there a better way to authenticate login?

GaryK

10:57 pm on Apr 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If there is a better, and yet still realistic method I've never seen it. I do take steps to make sure that any given account is only in use by one user at a time. Then again, my situation is very different than yours so I haven't had a lot of incentive to be more restrictive in who gets access to my content.

Patrick Taylor

11:30 am on May 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mcibor: There may be a way - with assigning cookie, eg after user authentification by email. I mean: send user an email with a link, then while he's visiting the page set a cookie on his pc.

This is quite a good method, and I've made one myself that works pretty well. Initially, it's computer-specific because of the cookie, but the registered user could access the content from another computer by sending to it the original email and clicking the link again. Of course this doesn't prevent the registrant sending that same email to others, so an option is to limit the registration to a single computer and price accordingly, and if they want to access from another one you can provide a suitable routine.

In the end, anyone can mimic someone else.

mcibor

1:19 pm on May 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is the algoruthm of authorising with cookie:

1. User pays you the price, says his email, username (pass by user, or you generate - that doesn't matter).
2. Create db record with id, username, pass, email, authorisation code (may be a random number/ascii), ip
3. You send an email to that user with url to authorise (url has authorisation code and id)
4. When user clicks on the url you check the ip and if valid you create a 1year/more year cookie with authorisation code

5. On login you check the username, pass and authorisation code from cookie. If the cookie's missing, but the ip is correct you create it, otherwise you restrict access.

Hope this helps!
Michal Cibor

PS. This way if the ip changes, but the cookie is still there, there won't be problem of logging in.

pheather

3:26 pm on May 1, 2005 (gmt 0)



One thing I've been playing with -- have used for manual authentication (i.e., I check the logs) is to verify the hostname of the signin. Instead of validating the IP, I call gethostbyaddr, filter out to just the domain name (because some domains have the IP embedded in them as in 123-456-567-890).

I've used it more for banning members than validating members. And yes, AOL is still a problem, but at least I ban only a portion instead of the entire AOL block.

percy05

10:38 pm on May 1, 2005 (gmt 0)

10+ Year Member



Thsnks for your very good ideas.
-GaryK, it sounds very interesting and useful, please, how do I do so? Originally I thought something like it to restrict access, and the idea is not bad...
-Patrick Taylor, I find it great. How can I limit the registration to a single pc, please?
-Mcibor, excellent! But please how can I create an authorisation code in a cookie? I thought that they only give us visitor's internet routines. Could you please give me more details about it?
-Pheaterm, interesting what you say about verifying the hostnames of the signin. Could you please give me more deatils about it?

GaryK

1:27 am on May 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's really amazingly easy to do and I'll be happy to share it with you.

When a user starts a session I insert a row into the OnlineNow table in my database. When their session ends I delete the row. If anyone else tries to use the same account while it's already in the OnlineNow table I redirect them to a page with a message telling them only one session at a time is allowed.

mcibor

8:49 am on May 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



True GaryK, but what happens if user closes the window, or shuts down the computer improperly, or just turns the internet off?

As to setting the auth code to a cookie it's fairly simple:

<?php
//create a random number
function rnd_no($length)
{
$chars = "abcdefghijklmnopqrstuvwxyz";
$chars .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$chars .= "1234567890";

$char_length = strlen($chars) - 1;
for($i = 0; $i < $length; $i++)
{
$pass .= $chars{rand(0, $char_length)};
}
return $pass;
}

//authentization code here
if($authentic){
$authcode = rnd_no(20);//20 chars random auth code
setcookie("user", $user.":".$rndpass, time() + 60*60*24*365);//valid one year. In one cookie I store username and authcode, not just authcode
//connect to db (not earlier, because you may have problems with setting the cookie)
mysql_query("INSERT INTO users (user, pass, authcode) VALUES('$username', '".md5($password)."', $authcode)") or die(mysql_error());//never store plain password, only it's hash
}?>


Hope this helps you
Michal Cibor

GaryK

3:12 pm on May 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



After a pre-determined amount of inactive time (10 minutes in this case) his/her session expires and the row is removed from the database. Does PHP not have the equivalent of ASP's global.asa file which lets you write code for four events: Application_OnStart/OnEnd, Session_OnStart/OnEnd? If not then you're right my approach wouldn't work very well.

percy05

4:03 pm on May 3, 2005 (gmt 0)

10+ Year Member



Thank you very much to all. I will try with it. But I will be very very thankful if there are more or other new ideas for doing a good authentication login. Thaks a lot, again. - Percy

Donniedarko

11:57 pm on May 7, 2005 (gmt 0)



Maybe you could try and setup your site, so that users log in with their microsoft .NET passport like alot of other websites.