IP authentication

A place to discuss development of the Xataface core.

IP authentication

Postby jbrnz » Mon Apr 27, 2009 9:46 pm

I have a DB that needs to be setup so that it logs in users by their IP address.

company with 20 computers who all need to access the same app and cannot be supplied with usernames and passwords for each computer.

Can Xataface do this?
jbrnz
 
Posts: 22
Joined: Mon Apr 20, 2009 11:20 am

Postby shannah » Tue Apr 28, 2009 12:58 pm

There are many ways to do this. PHP allows you to access this information via the $_SERVER['REMOTE_ADDR']

One way to do this is to create a simple authentication module to work the way you want it to. Here is a simple step by step example on how you might do this:

1. In your xataface/modules directory, create a module named 'Auth'.
2. In your 'Auth' directory, create a new directory named 'ip' (this can be called anything you want.. I called it ip to indicate that this is ip authentication).
3. In your 'ip' directory, create a php script called 'ip.php' with the following contents:
Code: Select all
<php>isLoggedIn() ){
        return Dataface_PermissionsTool::ALL();
    }
    return Dataface_PermissionsTool::NO_ACCESS();
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby jbrnz » Wed Apr 29, 2009 9:11 am

This is great. I do have a question - I have not setup a modules folder for my app and do not seem to have one in my xataface directory.

Would I create this directory in my app, or in the xataface directory?

(xataface/modules or myapp/modules)

Still somewhat green with xataface.
jbrnz
 
Posts: 22
Joined: Mon Apr 20, 2009 11:20 am

Postby shannah » Wed Apr 29, 2009 2:03 pm

The modules directory goes in the xataface folder (not your app's folder).

Also it looks like phpbb stripped some of the code from my original post.

Essentially the module just needs to contain a class named dataface_modules_ip and it should implement one method: authenticate()

You can see some examples of existing authentication modules in SVN:

http://weblite.ca/svn/dataface/modules/Auth/
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: IP authentication

Postby jbrnz » Wed Apr 07, 2010 2:09 pm

It has been a while since I last posted on this topic, but I am in the middle of putting together the ip authentication module for allowing access to my DB by providing a range of IP's. I am also green at php, but am getting a little more fluent with each day (not shown by post below, but true).

I have created a module directory called Auth and a directory called ip inside it

I also created a file called ip.php (I did not use isLoggedIn function, which might be my problem. Instead tried to change http cauth)

Code: Select all
class dataface_modules_ip {

   function authenticate(){
      $auth =& Dataface_AuthenticationTool::getInstance();
      if ( $auth->checkCredentials()){
         $creds = $this->getCredentials();
         $_SERVER['REMOTE_ADDR'] = $creds['REMOTE_ADDR'];
         return true;
      } else {
         return PEAR::raiseError('No credentials were included.', DATAFACE_E_REQUEST_NOT_HANDLED);
         
      }
      
   }

   function getCredentials(){
   
      $ip_address = ( isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null);
      return array('REMOTE_ADDR'=>$ip_address);
   }
}


My Conf.ini file reads

[_auth]
auth_type=ip
users_table="Users"
ip_address_column="ip_address"

Should I have an ip_table in place instead of Users?

I am not sure how to tell xataface where to find the ip addresses so that we can add different ip ranges specific to each user and the system will check them before allowing access.

I tried this and got nothing - I am finding the boards and documentation to be very helpful but could use some hints/help as to where to store the ip addresses that will be allowed access to the db.


Much appreciated
jbrnz
 
Posts: 22
Joined: Mon Apr 20, 2009 11:20 am

Re: IP authentication

Postby shannah » Thu Apr 08, 2010 9:55 am

The checkCredentials() method, by default will call your getCredentials() method and expect to receive UserName and Password, which it will check against the database. If you're implementing your own system, you probably want to skip the call to checkCredentials().. so your authenticate method would just look something like:

Code: Select all
function authenticate(){
      $auth =& Dataface_AuthenticationTool::getInstance();
       $creds = $this->getCredentials();
       if ( /* credentials look ok */ ){
          return true;
      }
      return PEAR::raiseError('No credentials were included.', DATAFACE_E_REQUEST_NOT_HANDLED);
         
     
     
   }
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Developers

Who is online

Users browsing this forum: No registered users and 11 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved