EllisLab text mark
Advanced Search
4 of 10
4
   
The Authentication Library 1.0.6
Posted: 08 October 2009 10:41 AM   [ # 51 ]   [ Rating: 0 ]
Joined: 2009-09-25
5 posts

jv1,

You are correct!

I commented out _generate() as you suggested and my page load times drop from ~2.2 seconds to .5 on localhost.

Thanks a lot, I’m not sure if there is a better long term fix, but this sure makes development faster.

Here is what the function now looks like :

    function _generate()
    {
$username = $this->CI->session->userdata('username');

$rand_url = 'http://random.org/strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new';
/*
if (ini_get('allow_url_fopen')) {
// Grab the random string using the easy version if we can
$token_source = fopen($rand_url, "r");
$token = fread($token_source, 20);
} elseif (function_exists(‘curl_version’)) {
// No easy version, so try cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $rand_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$token = curl_exec($ch);
curl_close($ch);
} else {
*/
// No love either way, generate a random string ourselves
$length = 20;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$token = '';
for ($i = 0; $i < $length; $i++) {
$token .= $characters[mt_rand(0, strlen($characters)-1)];
}
      //}

      $identifier = $username . $token;
      $identifier = $this->_salt($identifier);

      $this->CI->db->query(“UPDATE `$this->user_table` SET `identifier` = ‘$identifier’, `token` = ‘$token’ WHERE `username` = ‘$username’”);

      setcookie(“logged_in”, $identifier, time()+3600, ‘/’);
    }

Cheers
Sam

 
Posted: 08 October 2009 11:23 AM   [ # 52 ]   [ Rating: 0 ]
Joined: 2009-10-07
2 posts
samhQC - 08 October 2009 02:41 PM

jv1,

You are correct!

I commented out _generate() as you suggested and my page load times drop from ~2.2 seconds to .5 on localhost.

Thanks a lot, I’m not sure if there is a better long term fix, but this sure makes development faster.

...

Cheers
Sam

Well, the two seconds delay probably mean your site couldn’t resolv/connect to random.org and was only using the internal generator anyway smile

In php.net’s manual say this on the uniqid() function page:

Examples

If you need a unique identifier or token and you intend to give out that token
to the user via the network 
(i.esession cookies), it is recommended that you
use something along these lines:

This will create a 32 character identifier (a 128 bit hex numberthat is 
extremely difficult to predict
.

Example #1 uniqid() Example
<?php
// no prefix
// works only in PHP 5 and later versions
$token md5(uniqid());

// better, difficult to guess
$better_token md5(uniqid(mt_rand(), true));
?> 

But I’m not sure why it says it will only work with php5, as both functions are listed as php4/php5 compatible.

I’m considering using Auth but I don’t understand the rationaly behind connecting to an external site (random.org) to generate this token. Besides, the hosting provider I’m working with doesn’t support url_fopen or curl.

Most modern OSs should provide a reasonably good random generator. I’m working on OpenBSD and I’m sure it does, as most Linux distribs out there. I’m not so sure about it on the Windows systems.

Adam, are there other pieces of Auth that require external support? I don’t feel like reading it all smile

 
Posted: 08 October 2009 01:25 PM   [ # 53 ]   [ Rating: 0 ]
Joined: 2009-09-28
4 posts

If you open up the file libraries/Auth.php – you can see the two functions in there, login() and register(). That’s how it all works.

You could add some code into that file to shoot off a call to jQuery so when a user is registered/logged in you can do what you like with it.

Yes it’s not pretty but it’s the only way I can think of.


Thanks,
Adam

Yes I know , though the problem is I don’t know exactly where to add the code. That actually was the problem in the first place. I’d have to include a true, and if it fails, somehow capture the error messages.

I guess all in all, the problem is i don’t quite yet fully understand your coding, as in, the way you put the functions together.

Thanks,
Kenny

 
Posted: 08 October 2009 01:35 PM   [ # 54 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-04
356 posts
Raykoid666 - 08 October 2009 05:25 PM

If you open up the file libraries/Auth.php – you can see the two functions in there, login() and register(). That’s how it all works.

You could add some code into that file to shoot off a call to jQuery so when a user is registered/logged in you can do what you like with it.

Yes it’s not pretty but it’s the only way I can think of.


Thanks,
Adam

Yes I know , though the problem is I don’t know exactly where to add the code. That actually was the problem in the first place. I’d have to include a true, and if it fails, somehow capture the error messages.

I guess all in all, the problem is i don’t quite yet fully understand your coding, as in, the way you put the functions together.

Thanks,
Kenny

Those functions follow the pattern laid out in the user guide for the Form Validation Library, here. Have a read of that, it should clear everything up.


Thanks,
Adam

 Signature 

[ Adam Griffiths - Freelance Web Applications Developer ]
[ Follow me on Twitter ]

 
Posted: 09 October 2009 04:44 AM   [ # 55 ]   [ Rating: 0 ]
Joined: 2007-10-17
1 posts

Github seems to be freezing on loading http://www.google-analytics.com lol.. from here anyway

 
Posted: 09 October 2009 10:46 AM   [ # 56 ]   [ Rating: 0 ]
Joined: 2009-10-08
2 posts

Github is freezing on the same URL for me too… Is there a mirror somewhere?

 
Posted: 09 October 2009 12:22 PM   [ # 57 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6706 posts

GitHub doe’s not work with IE Browsers!

Enjoy
InsiteFX

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 09 October 2009 12:24 PM   [ # 58 ]   [ Rating: 0 ]
Joined: 2009-10-08
2 posts

I’m using Firefox 3.5.3?

 
Posted: 16 October 2009 06:06 AM   [ # 59 ]   [ Rating: 0 ]
Joined: 2009-10-16
3 posts
squarebones - 09 July 2009 07:09 PM

Can’t say how well I like this library as I haven’t been able to get it working. I followed the installation instructions and all is well until I actually try to access the register function (step 3). There is is no register function in the admin controller. Huh? Nor does login work by entering admin/login. All I get is a 404 page for both. I have renamed my various CI folders, but noted that in the config array so CI knows where to find everything. And my initial controller works to load up a simple construction page, so I know the CI install is good (not my first time using CI, by the way. About my fifth, actually).

I’m kind of stuck now. Is there perhaps something else I need to change to get this working? I know this isn’t much information to go on, so ask if you need more to make an educated guess.

Thank you.

Have same problem 404 Page. All setup from clean CI. Anybody made it works? Need help with it.

 
Posted: 16 October 2009 06:07 AM   [ # 60 ]   [ Rating: 0 ]
Joined: 2009-10-16
1 posts

Are you expecting to add a ‘Forgotten Password’ type process to the library anytime soon? It’d be great to see that added in. Since my application is built upon your library, it looks like I’m going to be adding that no matter what.

I’d be interested in helping you code that, you can find me on github with the same handle as my CI forums handle if you want to chat futher about it before I dive in.

 
Posted: 16 October 2009 07:19 AM   [ # 61 ]   [ Rating: 0 ]
Joined: 2009-10-16
3 posts

Hi all. I compelled it to work, but I got anothe problem, it doesn`t want to work with Template CI Library (http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html)

I replace any where line like
$this->auth->view(‘dashboard’)

with

$this->template->write_view(‘content’,    $this->auth->view(‘dashboard’));
$this->template->render();

But it not work. Can anybody helps me?

 
Posted: 16 October 2009 07:33 AM   [ # 62 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-04
356 posts
wildarp - 16 October 2009 11:19 AM

Hi all. I compelled it to work, but I got anothe problem, it doesn`t want to work with Template CI Library (http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html)

I replace any where line like
$this->auth->view(‘dashboard’)

with

$this->template->write_view(‘content’,    $this->auth->view(‘dashboard’));
$this->template->render();

But it not work. Can anybody helps me?

In that case you’ll need to manually include the path to the view folder and the headers and footers. I’ve never used the Template Library you linked to, so this code is all just a guess form what you’ve put in your post.

$this->template->write_view('header',     $this->load->view('auth/header'));
$this->template->write_view('content',     $this->load->view('auth/dashboard'));
$this->template->write_view('footer',     $this->load->view('auth/footer'));
$this->template->render(); 

Hopefully this helps you out.

 

Thanks,
Adam

 Signature 

[ Adam Griffiths - Freelance Web Applications Developer ]
[ Follow me on Twitter ]

 
Posted: 24 October 2009 04:28 AM   [ # 63 ]   [ Rating: 0 ]
Joined: 2009-10-15
3 posts

Hi,

Just wanted to say I finally got it working.

I had database trouble. What I discovered was that importing the provided dump.sql file via phpMyAdmin, the ci_ prefix was trashed on the users and groups tables.

After adding the prefix to the tables I was able to successfully open the registration page, change my new user to admin, reauthenticate, and see the manage users options.

Im impressed overall. Definitely will be playing with this library over the next few weeks. See what I can do with it. smile

 
Posted: 01 November 2009 06:02 PM   [ # 64 ]   [ Rating: 0 ]
Joined: 2009-11-01
1 posts
function _verify_cookie()
{
    
if((array_key_exists('login_attempts'$_COOKIE)) && ($_COOKIE['login_attempts'>= 5))
    
{
        $username 
$this->CI->session->userdata('username');
        
$userdata $this->CI->db->query("SELECT * FROM `$this->user_table` WHERE `z_username` = '$username'");
        
        
$result $userdata->row();

        
$identifier $result->z_username $result->token;
        
$identifier $this->_salt($identifier);
        
        if(
$identifier !== $_COOKIE['logged_in'])
        
{
            $this
->CI->session->sess_destroy();
            
            
show_error($this->CI->lang->line('logout_perms_error'));
        
}
    }
    
else
    
{
        $this
->_generate();
    
}

Is this correct?

Right now, if you are logged in it generates a new identifier every page load. Should it not be, that if there is no cookie, it should generate an identifier?

 
Posted: 02 November 2009 11:39 PM   [ # 65 ]   [ Rating: 0 ]
Joined: 2009-10-20
46 posts

Hello, I’m having troubles with this:

A Database Error Occurred
Error Number: 1364

Field ‘token’ doesn’t have a default value

INSERT INTO `users` (username, email, password) VALUES (‘admin’, ‘alfjoin@gmail.com’, ‘xxxxxxxxxxxxxxxxxxxxxxxxxx’)

Its shown when I try to register a new user :/ Any Idea?

 
4 of 10
4