<commit_before># Authlogic

An unobtrusive ruby authentication library based on ActiveRecord.

[![Gem Version][5]][6] [![Build Status][1]][2] [![Code Climate][7]][8] [![Dependency Status][3]][4]

[![Coverage Status](https://coveralls.io/repos/github/binarylogic/authlogic/badge.svg?branch=master)](https://coveralls.io/github/binarylogic/authlogic?branch=master)


## Sponsors

[![Timber Logging](http://res.cloudinary.com/timber/image/upload/v1490556810/pricing/sponsorship.png)](https://timber.io?utm_source=github&utm_medium=authlogic)

[Tail Authlogic users](https://timber.io/docs/app/console/tail-a-user) in your logs!

## Documentation

| Version     | Documentation |
| ----------- | ------------- |
| Unreleased  | https://github.com/binarylogic/authlogic/blob/master/README.md |
| 6.0.0       | https://github.com/binarylogic/authlogic/blob/v6.0.0/README.md |
| 5.1.0       | https://github.com/binarylogic/authlogic/blob/v5.1.0/README.md |
| 4.5.0       | https://github.com/binarylogic/authlogic/blob/v4.5.0/README.md |
| 3.7.0       | https://github.com/binarylogic/authlogic/blob/v3.7.0/README.md |
| 2.1.11      | https://github.com/binarylogic/authlogic/blob/v2.1.11/README.rdoc |
| 1.4.3       | https://github.com/binarylogic/authlogic/blob/v1.4.3/README.rdoc |

## Table of Contents

- [1. Introduction](#1-introduction)
  - [1.a. Overview](#1a-overview)
  - [1.b. Reference Documentation](#1b-reference-documentation)
- [2. Rails](#2-rails)
  - [2.a. The users table](#2a-the-users-table)
  - [2.b. Controller](#2b-controller)
  - [2.c. View](#2c-view)
  - [2.d. CSRF Protection](#2d-csrf-protection)
- [3. Testing](#3-testing)
- [4. Helpful links](#4-helpful-links)
- [5. Add-ons](#5-add-ons)
- [6. Internals](#6-internals)
- [7. Extending](#7-extending)
- [90. Compatibility](#90-compatibility)

## 1. Introduction

### 1.a. Overview

Authlogic introduces a new type of model. You can have as many as you want, and
name them whatever you want, just like your other models. In this example, we
want to authenticate with our `User` model, which is inferred from the name:

```ruby
class UserSession < Authlogic::Session::Base
  # specify configuration here, such as:
  # logout_on_timeout true
  # ...many more options in the documentation
end
```

In a `UserSessionsController`, login the user by using it just like your other models:

```ruby
UserSession.create(:login => "bjohnson", :password => "<PASSWORD>", :remember_me => true)

session = UserSession.new(:login => "bjohnson", :password => "<PASSWORD>", :remember_me => true)
session.save

# requires the authlogic-oid "add on" gem
UserSession.create(:openid_identifier => "identifier", :remember_me => true)

# skip authentication and log the user in directly, the true means "remember me"
UserSession.create(my_user_object, true)
```

The above handles the entire authentication process for you by:

1. authenticating (i.e. **validating** the record)
2. sets up the proper session values and cookies to persist the session (i.e. **saving** the record).

You can also log out (i.e. **destroying** the session):

``` ruby
session.destroy
```

After a session has been created, you can persist it (i.e. **finding** the
record) across requests. Thus keeping the user logged in:

``` ruby
session = UserSession.find
```

To get all of the nice authentication functionality in your model just do this:

```ruby
class User < ApplicationRecord
  acts_as_authentic do |c|
    c.my_config_option = my_value
  end # the configuration block is optional
end
```

It is also "smart" in the sense that if a login or username field
is present it will use that to authenticate, if not it will look for
an email field. This is all configurable, but for 99% of cases the above
is all you will need to do.

You may specify how passwords are cryptographically hashed (or encrypted) by
setting the Authlogic::CryptoProvider option:

``` ruby
c.crypto_provider = Authlogic::CryptoProviders::BCrypt
```

Also, sessions are automatically maintained. You can switch this on and off with
configuration, but the following will automatically log a user in after a
successful registration:

``` ruby
User.create(params[:user])
```

You can switch this on and off with the following configuration:

```ruby
class User < ApplicationRecord
  acts_as_authentic do |c|
    c.log_in_after_create = false
  end # the configuration block is optional
end
```

Authlogic also updates the session when the user changes his/her password. You can also switch this on and off with the following configuration:

```ruby
class User < ApplicationRecord
  acts_as_authentic do |c|
    c.log_in_after_password_change = false
  end # the configuration block is optional
end
```

Authlogic is very flexible, it has a strong public API and a plethora of hooks
to allow you to modify behavior and extend it. Check out the helpful links below
to dig deeper.

### 1.b. Reference Documentation

This README is just an introduction, but we also have [reference
documentation](http://www.rubydoc.info/github/binarylogic/authlogic).

**To use the reference documentation, you must understand how Authlogic's
code is organized.** There are 2 models, your Authlogic model and your
ActiveRecord model:

1. **Authlogic::Session**, your session models that
  extend `Authlogic::Session::Base`.
2. **Authlogic::ActsAsAuthentic**, which adds in functionality to your
  ActiveRecord model when you call `acts_as_authentic`.

## 2. Rails
<commit_msg>Add a note on how to install gem<commit_after># Authlogic

An unobtrusive ruby authentication library based on ActiveRecord.

[![Gem Version][5]][6] [![Build Status][1]][2] [![Code Climate][7]][8] [![Dependency Status][3]][4]

[![Coverage Status](https://coveralls.io/repos/github/binarylogic/authlogic/badge.svg?branch=master)](https://coveralls.io/github/binarylogic/authlogic?branch=master)


## Sponsors

[![Timber Logging](http://res.cloudinary.com/timber/image/upload/v1490556810/pricing/sponsorship.png)](https://timber.io?utm_source=github&utm_medium=authlogic)

[Tail Authlogic users](https://timber.io/docs/app/console/tail-a-user) in your logs!

## Documentation

| Version     | Documentation |
| ----------- | ------------- |
| Unreleased  | https://github.com/binarylogic/authlogic/blob/master/README.md |
| 6.0.0       | https://github.com/binarylogic/authlogic/blob/v6.0.0/README.md |
| 5.1.0       | https://github.com/binarylogic/authlogic/blob/v5.1.0/README.md |
| 4.5.0       | https://github.com/binarylogic/authlogic/blob/v4.5.0/README.md |
| 3.7.0       | https://github.com/binarylogic/authlogic/blob/v3.7.0/README.md |
| 2.1.11      | https://github.com/binarylogic/authlogic/blob/v2.1.11/README.rdoc |
| 1.4.3       | https://github.com/binarylogic/authlogic/blob/v1.4.3/README.rdoc |

## Table of Contents

- [1. Introduction](#1-introduction)
  - [1.a. Overview](#1a-overview)
  - [1.b. Reference Documentation](#1b-reference-documentation)
- [2. Rails](#2-rails)
  - [2.a. The users table](#2a-the-users-table)
  - [2.b. Controller](#2b-controller)
  - [2.c. View](#2c-view)
  - [2.d. CSRF Protection](#2d-csrf-protection)
- [3. Testing](#3-testing)
- [4. Helpful links](#4-helpful-links)
- [5. Add-ons](#5-add-ons)
- [6. Internals](#6-internals)
- [7. Extending](#7-extending)
- [90. Compatibility](#90-compatibility)

## 1. Introduction

### 1.a. Overview

Authlogic introduces a new type of model. You can have as many as you want, and
name them whatever you want, just like your other models. In this example, we
want to authenticate with our `User` model, which is inferred from the name:

```ruby
class UserSession < Authlogic::Session::Base
  # specify configuration here, such as:
  # logout_on_timeout true
  # ...many more options in the documentation
end
```

In a `UserSessionsController`, login the user by using it just like your other models:

```ruby
UserSession.create(:login => "bjohnson", :password => "<PASSWORD>", :remember_me => true)

session = UserSession.new(:login => "bjohnson", :password => "<PASSWORD>", :remember_me => true)
session.save

# requires the authlogic-oid "add on" gem
UserSession.create(:openid_identifier => "identifier", :remember_me => true)

# skip authentication and log the user in directly, the true means "remember me"
UserSession.create(my_user_object, true)
```

The above handles the entire authentication process for you by:

1. authenticating (i.e. **validating** the record)
2. sets up the proper session values and cookies to persist the session (i.e. **saving** the record).

You can also log out (i.e. **destroying** the session):

``` ruby
session.destroy
```

After a session has been created, you can persist it (i.e. **finding** the
record) across requests. Thus keeping the user logged in:

``` ruby
session = UserSession.find
```

To get all of the nice authentication functionality in your model just do this:

```ruby
class User < ApplicationRecord
  acts_as_authentic do |c|
    c.my_config_option = my_value
  end # the configuration block is optional
end
```

It is also "smart" in the sense that if a login or username field
is present it will use that to authenticate, if not it will look for
an email field. This is all configurable, but for 99% of cases the above
is all you will need to do.

You may specify how passwords are cryptographically hashed (or encrypted) by
setting the Authlogic::CryptoProvider option:

``` ruby
c.crypto_provider = Authlogic::CryptoProviders::BCrypt
```

Also, sessions are automatically maintained. You can switch this on and off with
configuration, but the following will automatically log a user in after a
successful registration:

``` ruby
User.create(params[:user])
```

You can switch this on and off with the following configuration:

```ruby
class User < ApplicationRecord
  acts_as_authentic do |c|
    c.log_in_after_create = false
  end # the configuration block is optional
end
```

Authlogic also updates the session when the user changes his/her password. You can also switch this on and off with the following configuration:

```ruby
class User < ApplicationRecord
  acts_as_authentic do |c|
    c.log_in_after_password_change = false
  end # the configuration block is optional
end
```

Authlogic is very flexible, it has a strong public API and a plethora of hooks
to allow you to modify behavior and extend it. Check out the helpful links below
to dig deeper.

### 1.b. Reference Documentation

This README is just an introduction, but we also have [reference
documentation](http://www.rubydoc.info/github/binarylogic/authlogic).

**To use the reference documentation, you must understand how Authlogic's
code is organized.** There are 2 models, your Authlogic model and your
ActiveRecord model:

1. **Authlogic::Session**, your session models that
  extend `Authlogic::Session::Base`.
2. **Authlogic::ActsAsAuthentic**, which adds in functionality to your
  ActiveRecord model when you call `acts_as_authentic`.

### 1.c. Installation

To install Authlogic, add this to your Gemfile:

 `gem 'authlogic'`

 And run `bundle install`.

## 2. Rails

{'fraction_non_alphanumeric': 0.12765572733025948, 'fraction_numerical': 0.01762950908597776, 'mean_word_length': 4.2476280834914615, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 22, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1128422', 'n_tokens_mistral': 3679, 'n_tokens_neox': 3381, 'n_words': 1139}