398

I see there are a few. Which ones are maintained and easy to use? What are their pros and cons?

Shog9
  • 146,212
  • 34
  • 221
  • 231
GavinR
  • 5,816
  • 7
  • 28
  • 43
  • 8
    If you are still interested, look at Tank Auth. I just updated my post below after reviewing it, and it is excellent. – Jens Roland May 14 '10 at 16:12

11 Answers11

466

Update (May 14, 2010):

It turns out, the russian developer Ilya Konyukhov picked up the gauntlet after reading this and created a new auth library for CI based on DX Auth, following the recommendations and requirements below.

And the resulting Tank Auth is looking like the answer to the OP's question. I'm going to go out on a limb here and call Tank Auth the best authentication library for CodeIgniter available today. It's a rock-solid library that has all the features you need and none of the bloat you don't:

Tank Auth

Pros

  • Full featured
  • Lean footprint (20 files) considering the feature set
  • Very good documentation
  • Simple and elegant database design (just 4 DB tables)
  • Most features are optional and easily configured
  • Language file support
  • reCAPTCHA supported
  • Hooks into CI's validation system
  • Activation emails
  • Login with email, username or both (configurable)
  • Unactivated accounts auto-expire
  • Simple yet effective error handling
  • Uses phpass for hashing (and also hashes autologin codes in the DB)
  • Does not use security questions
  • Separation of user and profile data is very nice
  • Very reasonable security model around failed login attempts (good protection against bots and DoS attacks)

(Minor) Cons

  • Lost password codes are not hashed in DB
  • Includes a native (poor) CAPTCHA, which is nice for those who don't want to depend on the (Google-owned) reCAPTCHA service, but it really isn't secure enough
  • Very sparse online documentation (minor issue here, since the code is nicely documented and intuitive)

Download Tank Auth here


Original answer:

I've implemented my own as well (currently about 80% done after a few weeks of work). I tried all of the others first; FreakAuth Light, DX Auth, Redux, SimpleLogin, SimpleLoginSecure, pc_user, Fresh Powered, and a few more. None of them were up to par, IMO, either they were lacking basic features, inherently INsecure, or too bloated for my taste.

Actually, I did a detailed roundup of all the authentication libraries for CodeIgniter when I was testing them out (just after New Year's). FWIW, I'll share it with you:

DX Auth

Pros

  • Very full featured
  • Medium footprint (25+ files), but manages to feel quite slim
  • Excellent documentation, although some is in slightly broken English
  • Language file support
  • reCAPTCHA supported
  • Hooks into CI's validation system
  • Activation emails
  • Unactivated accounts auto-expire
  • Suggests grc.com for salts (not bad for a PRNG)
  • Banning with stored 'reason' strings
  • Simple yet effective error handling

Cons

  • Only lets users 'reset' a lost password (rather than letting them pick a new one upon reactivation)
  • Homebrew pseudo-event model - good intention, but misses the mark
  • Two password fields in the user table, bad style
  • Uses two separate user tables (one for 'temp' users - ambiguous and redundant)
  • Uses potentially unsafe md5 hashing
  • Failed login attempts only stored by IP, not by username - unsafe!
  • Autologin key not hashed in the database - practically as unsafe as storing passwords in cleartext!
  • Role system is a complete mess: is_admin function with hard-coded role names, is_role a complete mess, check_uri_permissions is a mess, the whole permissions table is a bad idea (a URI can change and render pages unprotected; permissions should always be stored exactly where the sensitive logic is). Dealbreaker!
  • Includes a native (poor) CAPTCHA
  • reCAPTCHA function interface is messy

FreakAuth Light

Pros

  • Very full featured
  • Mostly quite well documented code
  • Separation of user and profile data is a nice touch
  • Hooks into CI's validation system
  • Activation emails
  • Language file support
  • Actively developed

Cons

  • Feels a bit bloated (50+ files)
  • And yet it lacks automatic cookie login (!)
  • Doesn't support logins with both username and email
  • Seems to have issues with UTF-8 characters
  • Requires a lot of autoloading (impeding performance)
  • Badly micromanaged config file
  • Terrible View-Controller separation, with lots of program logic in views and output hard-coded into controllers. Dealbreaker!
  • Poor HTML code in the included views
  • Includes substandard CAPTCHA
  • Commented debug echoes everywhere
  • Forces a specific folder structure
  • Forces a specific Ajax library (can be switched, but shouldn't be there in the first place)
  • No max limit on login attempts - VERY unsafe! Dealbreaker!
  • Hijacks form validation
  • Uses potentially unsafe md5 hashing

pc_user

Pros

  • Good feature set for its tiny footprint
  • Lightweight, no bloat (3 files)
  • Elegant automatic cookie login
  • Comes with optional test implementation (nice touch)

Cons

  • Uses the old CI database syntax (less safe)
  • Doesn't hook into CI's validation system
  • Kinda unintuitive status (role) system (indexes upside down - impractical)
  • Uses potentially unsafe sha1 hashing

Fresh Powered

Pros

  • Small footprint (6 files)

Cons

  • Lacks a lot of essential features. Dealbreaker!
  • Everything is hard-coded. Dealbreaker!

Redux / Ion Auth

According to the CodeIgniter wiki, Redux has been discontinued, but the Ion Auth fork is going strong: https://github.com/benedmunds/CodeIgniter-Ion-Auth

Ion Auth is a well featured library without it being overly heavy or under advanced. In most cases its feature set will more than cater for a project's requirements.

Pros

  • Lightweight and simple to integrate with CodeIgniter
  • Supports sending emails directly from the library
  • Well documented online and good active dev/user community
  • Simple to implement into a project

Cons

  • More complex DB schema than some others
  • Documentation lacks detail in some areas

SimpleLoginSecure

Pros

  • Tiny footprint (4 files)
  • Minimalistic, absolutely no bloat
  • Uses phpass for hashing (excellent)

Cons

  • Only login, logout, create and delete
  • Lacks a lot of essential features. Dealbreaker!
  • More of a starting point than a library

Don't get me wrong: I don't mean to disrespect any of the above libraries; I am very impressed with what their developers have accomplished and how far each of them have come, and I'm not above reusing some of their code to build my own. What I'm saying is, sometimes in these projects, the focus shifts from the essential 'need-to-haves' (such as hard security practices) over to softer 'nice-to-haves', and that's what I hope to remedy.

Therefore: back to basics.

Authentication for CodeIgniter done right

Here's my MINIMAL required list of features from an authentication library. It also happens to be a subset of my own library's feature list ;)

  1. Tiny footprint with optional test implementation
  2. Full documentation
  3. No autoloading required. Just-in-time loading of libraries for performance
  4. Language file support; no hard-coded strings
  5. reCAPTCHA supported but optional
  6. Recommended TRUE random salt generation (e.g. using random.org or random.irb.hr)
  7. Optional add-ons to support 3rd party login (OpenID, Facebook Connect, Google Account, etc.)
  8. Login using either username or email
  9. Separation of user and profile data
  10. Emails for activation and lost passwords
  11. Automatic cookie login feature
  12. Configurable phpass for hashing (properly salted of course!)
  13. Hashing of passwords
  14. Hashing of autologin codes
  15. Hashing of lost password codes
  16. Hooks into CI's validation system
  17. NO security questions!
  18. Enforced strong password policy server-side, with optional client-side (Javascript) validator
  19. Enforced maximum number of failed login attempts with BEST PRACTICES countermeasures against both dictionary and DoS attacks!
  20. All database access done through prepared (bound) statements!

Note: those last few points are not super-high-security overkill that you don't need for your web application. If an authentication library doesn't meet these security standards 100%, DO NOT USE IT!

Recent high-profile examples of irresponsible coders who left them out of their software: #17 is how Sarah Palin's AOL email was hacked during the Presidential campaign; a nasty combination of #18 and #19 were the culprit recently when the Twitter accounts of Britney Spears, Barack Obama, Fox News and others were hacked; and #20 alone is how Chinese hackers managed to steal 9 million items of personal information from more than 70.000 Korean web sites in one automated hack in 2008.

These attacks are not brain surgery. If you leave your back doors wide open, you shouldn't delude yourself into a false sense of security by bolting the front. Moreover, if you're serious enough about coding to choose a best-practices framework like CodeIgniter, you owe it to yourself to at least get the most basic security measures done right.


<rant>

Basically, here's how it is: I don't care if an auth library offers a bunch of features, advanced role management, PHP4 compatibility, pretty CAPTCHA fonts, country tables, complete admin panels, bells and whistles -- if the library actually makes my site less secure by not following best practices. It's an authentication package; it needs to do ONE thing right: Authentication. If it fails to do that, it's actually doing more harm than good.

</rant>

/Jens Roland

Community
  • 1
  • 1
Jens Roland
  • 26,677
  • 14
  • 78
  • 102
  • 2
    Jens, you might want to look at Tank Auth which seems to have been created in response to your (excellent) post: http://codeigniter.com/forums/viewthread/110993/ – Richard M Aug 03 '09 at 14:50
  • Redux is no longer being maintained and I quote "It contains bugs, missing features and crap code so I would really recommend avoid using it." - http://codeigniter.com/forums/viewthread/145342/ – Ben Jul 21 '10 at 04:28
  • 8
    Can you update this post and compare with [Ion-Auth](http://github.com/benedmunds/CodeIgniter-Ion-Auth) (derived from dx-auth)? It seems like ion-auth is more up to date and active then tank-auth at this point in time. I want to know from a security perspective if it is as good as Tank-auth or not, because it has some additional features that might be useful. – Vijay May 13 '11 at 05:53
  • 1
    All these libraries use mysql.. however I use MongoDb which is a noSql database. Is there a library which works with MoongoDB? I tried converting one of the libraries above to insert into MongoDB instead of MySql but it is getting too complex and would like to know a library which already does this – Ninja Oct 19 '11 at 04:52
  • [Actually sha1 is more secure than md5....and newest recomendation is to use SHA2(SHA-224, SHA-256, SHA-384, and SHA-512) hashing....](http://en.wikipedia.org/wiki/SHA_hash_functions) – Nemke Aug 04 '09 at 09:42
  • Even though outdated, the information contained in that post is the *best* summary of what you should expect from your authentication mechanism. Thank you. – ack__ Sep 06 '12 at 22:26
  • Could you please define to me in No9 what exactly do you mean by a simple example?? – ltdev May 22 '13 at 12:37
  • 2
    @Lykos: Sure -- User data would be auth-specific data such as UserID, UserName, Email, PasswordHash, LastLoginTime, etc. Profile data should be stored in a separate DB table and could be anything, depending on the specific application. This could include things like birthday, gender, hometown, reputation score, etc. This way, the application developers can modify the ProfileData table in any way they like, without having to worry about the auth system suddenly breaking. – Jens Roland May 25 '13 at 16:28
  • thanks for the reply! I'm trying to create a simple custom auth library (that uses a MY_Model for all crud)for some projects at my college, and i'm looking for some guidelines/simple auth libraries to get some ideas. Do you know any simple examples on that please or tutorials?? – ltdev May 26 '13 at 12:25
  • @Lykos: There's nothing simple about it -- auth is full of little surprises and pitfalls, and any tutorial claiming to be 'simple' is bound to lead you into trouble. My advice would be to read through the source code for at least four of the top auth libraries for your framework of choice. – Jens Roland May 26 '13 at 20:01
  • Three years later I'm not sure thank auth is still the best solution. The project has slowly become outdated and others have moved on. (Ion Auth) – bottleboot Aug 07 '13 at 08:45
58

Note that the "comprehensive listing" by Jens Roland doesn't include user roles. If you're interested in assigning different user roles (like admin/user or admin/editor/user), these libraries allow it:

  • Ion_Auth (rewrite of Redux)
  • Redux
  • Backend Pro

Tank_Auth (#1 above in Jens's list) doesn't have user roles. I realize it's not exactly part of authentication, but since

  • authentication and role management are both handled upon page load
  • Both involve security
  • The same table/model can be used for both.
  • Both can be set up to load in the controller constructor (or even autoload)

It makes a LOT of sense to have one library to handle both, if you need it. I'm switching to Ion_Auth from Tank_Auth because of this.

Burton Kent
  • 788
  • 5
  • 10
37

Ion_auth! Looks very promising and small footprint! I like..

http://github.com/benedmunds/CodeIgniter-Ion-Auth

Marko
  • 1,485
  • 2
  • 13
  • 18
  • Ion Auth works fine for me too, has everything I need and nothing I don't (like secret questions and the likes). – SolidSmile Jun 30 '10 at 13:43
  • 1
    Ion Auth looks like the current leader in terms of usage, features and light-weight-ness. – pbreitenbach Jul 07 '10 at 12:43
  • 5
    I have tried both Tank Auth and Ion Auth and I can say that Tank Auth code is much more cleaner, easier to understand and easier to extend than Ion Auth. On the other side Ion Auth supports 'roles'. – Jonathan Oct 11 '11 at 10:06
30

I'm the developer of Redux Auth and some of the issues you mentioned have been fixed in the version 2 beta. You can download this off the offcial website with a sample application too.

  • Requires autoloading (impeding performance)
  • Uses the inherently unsafe concept of 'security questions'. Dealbreaker!

Security questions are now not used and a simpler forgotten password system has been put in place.

  • Return types are a bit of a hodgepodge of true, false, error and success codes

This was fixed in version 2 and returns boolean values. I hated the hodgepodge as much as you.

  • Doesn't hook into CI's validation system

The sample application uses the CI's validation system.

  • Doesn't allow a user to resend a 'lost password' code

Work in progress

I also implemented some other features such as email views, this gives you the choice of being able to use the CodeIgniter helpers in your emails.

It's still a work in progress so if have any more suggestions please keep them coming.

-Popcorn

Ps : Thanks for recommending Redux.

Svish
  • 138,188
  • 158
  • 423
  • 589
  • Just had a quick glance at the CI Forum thread and the roadmap. Looking good - with respect to the 'dynamic' salts, I recommend concatenating (reg. date) . (config file hash key) . (code or password) to thwart rainbow tables and brute force on a stolen database – Jens Roland Jan 29 '09 at 11:06
  • Also, I have some thoughts on auth best practices (http://stackoverflow.com/questions/549/the-definitive-guide-to-website-authentication-beta) and botnet throttling (http://stackoverflow.com/questions/479233/what-is-the-best-distributed-brute-force-countermeasure) you might want to run over – Jens Roland Jan 29 '09 at 11:10
14

I've come across Flexi Auth (http://haseydesign.com/flexi-auth/). It looks very promising, and I've started using it. It has wonderfful features. Fully integrates with CI, and comes with two different library files, in which one is very heavy loaded with all the functions and the other one contains only the validations.

One of the best is that the newly registered member gets temporary access for a given amount of time on the site, until they click on the link from their email and activate.

Suthan Bala
  • 2,774
  • 4
  • 29
  • 51
  • Thanks for this link. It has also another good feature Flexi Cart https://www.haseydesign.com/flexi-cart/ . – Vi_real May 09 '19 at 19:31
13

Maybe you'd find Redux suiting your needs. It's no overkill and comes packed solely with bare features most of us would require. The dev and contributors were very strict on what code was contributed.

This is the official page

Filip Dupanović
  • 28,429
  • 11
  • 76
  • 105
8

Ion_Auth beats tank_auth mainly for two reasons, user roles and documentation, these two are missing from tank_auth.

nedu
  • 81
  • 1
  • 1
6

I use a customized version of DX Auth. I found it simple to use, extremely easy to modify and it has a user guide (with great examples) that is very similar to Code Igniter's.

Jelani Harris
  • 804
  • 6
  • 5
4

Also take a look at BackendPro

Ultimately you will probably end up writing something custom, but there's nothing wrong with borrowing concepts from DX Auth, Freak Auth, BackendPro, etc.

My experiences with the packaged apps is they are specific to certain structures and I have had problems integrating them into my own applications without requiring hacks, then if the pre-package has an update, I have to migrate them in.

I also use Smarty and ADOdb in my CI code, so no matter what I would always end up making major code changes.

Adam
  • 6,790
  • 2
  • 23
  • 24
3

Tank Auth looks good but the documentation is just a one-page explanation of how to install, plus a quick run-down of each PHP file. At least that's all I found after lots of Googling. Maybe what people mean above when they say that Tank Auth is well-documented is that the code is well-commented. That's a good thing, but different than documentation. It would have been nice to have some documentation about how to integrate Tank Auth's features with your existing code.

3

I'm trying Ion_Auth and appreciate it, btw...

SimpleLoginSecure Makes authentication simple and secure.

Fabiano Shark
  • 325
  • 2
  • 5