Re: [PHP-PEAR] RFC on merge of PHPLib and Pear
[email protected] ((Kristian Koehntopp)) 10 Mar 2001 11:59:29 -0000
| Newsgroups | netuse.lists.php-pear |
|---|---|
| Message-ID | <[email protected]> |
In netuse.lists.php-pear you write:
>Can you use phplib's auth to authenticate someone by ip address?
class My_Auth extends Auth
function auth_preauth {
global $HTTP_SERVER_VARS;
if ($this->is_valid_ip($HTTP_SERVER_VARS["REMOTE_ADDR"]))
return md5($HTTP_SERVER_VARS["REMOTE_ADDR"]);
return false;
}
function is_valid_ip($ip) {
...
}
}
This solution does not even turn up a login screen, if the IP
address is valid. It will call auth_loginform(), if the IP
address is invalid. You may supply an error message here, thus
disabling login for people with the wrong IP, or you may
implement a standard PHPLIB loginform, allowing people from
invalid IPs to login regularly (the equivalent of Satisfy Any in
an Apache combined require/allow scenario).
The solution shown above will assign a different UID for
different IPs. This may not be what you want, you may return
different UIDs for different network blocks, or run all IPs as a
single UID, depending on your needs. Just set the return value
as you see fit.
You may also want to block all accesses from invalid IPs, and
force users from valid IPs to login, thus implementing
essentially Satisfy All in a combined require/allow scenario. To
do this, you'd not implement auth_preauth, and write an
auth_validatelogin method that checks IP _and_ username/password
combination.
You are free to select the data source for usernames, passwords
and/or IP numbers. I have seen databases, LDAP servers, SMB
servers/domain controllers and plain text files as data sources
for PHPLIB Auth deployments.
Kristian