Skip to content

Instantly share code, notes, and snippets.

View rreas's full-sized avatar

Russell Reas rreas

  • Allen Institute for AI
  • Seattle, WA
View GitHub Profile
@embs
embs / Rails 3.1 authentication from scratch.markdown
Created June 12, 2012 17:49
Authentication from Scratch with Rails 3.2.5

Authentication from Scratch with Rails 3.2.5

Rails 3.1 gives us a really easy way to authenticate users in our app: http_basic_authenticate_with. Using it, all we need to do is create a model for the user (certainly, User model :P) with an attribute called password_digest and some views feature for login and register users. After all, let's relax and let Rails do the hard work.

What we'll need

Gemfile

gem 'bcrypt-ruby', '~> 3.0.0'

Model

First at all, an User model which we can generate by following: rails g model user email:string password_digest:string and then add the following methodo call to generated class: has_secure_password