Authlogic splits authentication into a session model and an ActiveRecord model
Authlogic is a Ruby library for implementing user authentication and managing sessions in Rails.
At a glance
- What is it?
- Authlogic is a Ruby authentication library for Rails apps that keeps login as two ordinary objects: a session class you name yourself and an ActiveRecord model extended by acts_as_authentic. It trades a generated login flow for per-record control, and its ActiveRecord coupling narrows where it can run.
- Who is it for?
- Adopt Authlogic if your Rails app already sits on ActiveRecord and you want to own the controller and view code rather than accept a generated login surface. Do not adopt it for a non-Rails stack, for a Mongoid-only model, or when a security team wants packaged password policy rather than hand-written validations.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Activity is slowing. The repository last received commits 9 months ago.
- What is it written in?
- Mainly Ruby, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- binarylogic/authlogic4,335 ★ · -11
| Repository | 2026-08-13 | 2026-11-25 |
|---|---|---|
| binarylogic/authlogic | 4.3k | 4.3k |
-11 Stars in the last 104 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Authlogic runs on two models, and neither one is generated for you
Most Rails authentication libraries hand you a login form, routes and a User model in one move. Authlogic declines that trade and gives you two things to wire yourself. One is a session model that inherits from Authlogic::Session::Base. The other is the acts_as_authentic class method, which mixes functionality into an existing ActiveRecord class.
The split is deliberate, and the reference documentation says you cannot read one half without the other. Authlogic::Session owns the request lifecycle: it validates credentials, writes the session values and cookies that persist a login, finds an existing session on later requests, and destroys it on logout. Authlogic::ActsAsAuthentic adds functionality to your ActiveRecord model when you call acts_as_authentic; the README's migration example ties its Email, Login, Password, PersistenceToken and SingleAccessToken modules to columns on the users table.
Because you name the session class, you can have as many as you want and call them whatever you like, the same way you name User or Order. A class that logs in against your customer records is a name you choose, and it inherits the same behaviour.
acts_as_authentic guesses your login field from the columns you already have
The active side of the library reads your schema before it reads your config. If a login or username field is present on the table, authentication uses that; if not, it falls back to an email field. Both choices are configurable, and the overview is blunt that for most applications the single no-argument call is enough.
The migration example carries many columns because, per the README, it enables all of Authlogic's features. Five comments in it name the module that needs each column: Authlogic::ActsAsAuthentic::Email, Login, Password, PersistenceToken, SingleAccessToken. For the full feature set, the example's table holds a crypted_password and a password_salt, a persistence_token, and both an email and a login. Two of the five columns in the example also carry unique indexes.
Hashing is a separate decision you make explicitly. Setting the Authlogic::CryptoProvider option names the algorithm, and the example given is Authlogic::CryptoProviders::BCrypt. The overview names no default, so an application that stores credentials should set this rather than inherit it.
Two Gemfile lines and one model call stand between you and a working login
Installation is the shortest part of the whole process. Add the gem to your Gemfile:
gem 'authlogic'Then resolve it:
bundle installWith the gem present, the model side is one call inside your User class:
class User < ApplicationRecord
acts_as_authentic
endThe optional block exists for configuration, and the overview also shows the form where a single option is assigned:
class User < ApplicationRecord
acts_as_authentic do |c|
c.my_config_option = my_value
end
endThat is the whole first run. The README's installation section lists no generator or install task, and the users table section gives the migration as an example for you to write, so plan the migration before you write the controller.
UserSession.create, UserSession.find and session.destroy are the entire login API
The session model is used the way you would use any other object. One call authenticates the credentials and persists them, writing the session values and cookies:
UserSession.create(:login => "bjohnson", :password => "my password", :remember_me => true)If you need the instance rather than the return value, build it and save it in two steps:
session = UserSession.new(:login => "bjohnson", :password => "my password", :remember_me => true)
session.saveOn any later request, find the session again to recover the user:
session = UserSession.findAnd logout is a destroy:
session.destroyThe overview is explicit about what each word covers: authenticating means validating the record, saving means setting the proper session values and cookies to persist it, and finding means recovering that record across requests. One more shortcut exists for code paths that already hold a user object, where the true argument means remember me:
UserSession.create(my_user_object, true)That last form is a direct login with no password check, so it belongs only behind code that has already authenticated the record itself.
log_in_after_create and log_in_after_password_change log users in without a form
Session maintenance is automatic, and two switches decide when it happens. Create a user with plain ActiveRecord and Authlogic signs that user in:
User.create(params[:user])The call looks like ordinary record creation, but on success the user already has a session. Turning that off is one option inside the acts_as_authentic block:
class User < ApplicationRecord
acts_as_authentic do |c|
c.log_in_after_create = false
end
endPassword changes get the same treatment. Authlogic updates the session when the password changes, controlled by log_in_after_password_change, set in the same way. A commented line in the first example, logout_on_timeout true, points at a configuration option on the UserSession class rather than on the User model.
The failure mode worth planning for is at your API layer. A JSON endpoint that answers a signup with a created record is running code that also opens a session and sets cookies, which a stateless client has no use for and may not expect. The switch is the fix, but it has to be set deliberately rather than discovered in production.
The migration example stops mid-column, so the single access token schema is yours to name
The users table example in the walkthrough is the most useful thing in it, and it is cut off partway through. After the SingleAccessToken comment the snippet ends on an unfinished line, t.string with no column name after it. So the email, login, crypted_password, password_salt and persistence_token columns are given to you verbatim, along with unique indexes on email and persistence_token, while the token columns remain undocumented in that example.
That gap matters more than a formatting slip. You cannot infer the column's name from a comment whose value the README stops printing.
A second detail rewards a close read. The documentation table at the top of the README lists versions from 1.4.3 up to 6.6.1, each pointing at its own tagged README, yet the repository has no GitHub releases, so upgrades are found through tags rather than a release feed. And the model example carries a migration note of its own: automatic validations from before version 5 were deprecated in 4.4.0, with the write-up in doc/use_normal_rails_validation.md. Anyone arriving from an Authlogic 4 codebase inherits that validation rewrite as part of the upgrade, not as an optional tidy-up.
Where Authlogic and Devise draw the line differently
Devise and Authlogic both arrive as gems in a Rails Gemfile, but they draw the line in a different place. Devise ships a substantial framework layer: a set of authentication modules with their own controllers, views, routes and mappings, and the application configures and extends that shipped structure. Authlogic ships no interface at all. It supplies the session and record behaviour and expects your controller, your views and your routes to call it.
The practical difference is where your code lives. With Authlogic the login view is a file you write, and UserSession.find is a line you place where you want a current user. With Devise that wiring is generated and modified through mappings and modules rather than by calling methods from a session class you named.
The cost runs the other way too. Authlogic's restraint is only free because you own the consequences: session fixation handling, cookie flags and redirect behaviour all sit in code you are responsible for reading. The overview advertises a strong public API and many hooks, and that extensibility is real, but it also means the security posture of your login flow is yours to audit. Neither library is better here. The question is whether you want to write that flow or inherit it.
Editorial conclusion
Adopt Authlogic if your Rails app already sits on ActiveRecord and you want to own the controller and view code rather than accept a generated login surface. Do not adopt it for a non-Rails stack, for a Mongoid-only model, or when a security team wants packaged password policy rather than hand-written validations. Before anything else, open the migration you write for acts_as_authentic and check that the crypted_password, password_salt and persistence_token columns match your existing users table, since Authlogic will not add them for you.
Frequently asked questions
Does Authlogic work with ActionController::API?
The walkthrough includes a section on ActionController::API alongside the controller, route and view guidance. The rest of the setup is written for a full ActionController application.
How do I choose a password hashing provider in Authlogic?
Set the Authlogic::CryptoProvider option, with the example given being Authlogic::CryptoProviders::BCrypt.
What does acts_as_authentic add to my Authlogic model?
Calling acts_as_authentic adds Authlogic::ActsAsAuthentic functionality to the ActiveRecord class; the README's migration example ties its Email, Login, Password, PersistenceToken and SingleAccessToken modules to columns on the users table. Validating email, login and password is left to you, since the automatic validations were deprecated in 4.4.0.
Which columns does Authlogic need on my users table?
The migration example gives email, login, crypted_password, password_salt and persistence_token, with unique indexes on email and persistence_token. The columns for Authlogic::ActsAsAuthentic::SingleAccessToken are named in a comment that the example leaves unfinished.
How do I log a user in after Authlogic registers them?
That is the default: creating a user with User.create logs them in, and the session is kept valid when the password changes. Set log_in_after_create or log_in_after_password_change to false inside the acts_as_authentic block to turn either behaviour off.
Is the Authlogic repository still being worked on?
The repository is not archived, and its last push was on 2026-02-08. Versions are reached through tags such as 6.6.1 rather than through GitHub releases.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/binarylogic-authlogic)Star history chart for your README
[](https://hysenlabs.com/projects/binarylogic-authlogic)Was this useful?