mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
Tidying up encryptors.
This commit is contained in:
@@ -18,14 +18,19 @@ module Devise
|
||||
:unconfirmed => :failure
|
||||
}
|
||||
|
||||
# Declare encryptors length which are used in migrations.
|
||||
ENCRYPTORS_LENGTH = {
|
||||
:sha1 => 40,
|
||||
:sha512 => 128,
|
||||
:clearance_sha1 => 40,
|
||||
:restful_authentication_sha1 => 40,
|
||||
:authlogic_sha512 => 128
|
||||
}
|
||||
|
||||
# Used to encrypt password. Please generate one with rake secret
|
||||
mattr_accessor :pepper
|
||||
@@pepper = nil
|
||||
|
||||
# Used to define the password encryption algorithm
|
||||
mattr_accessor :encryptor
|
||||
@@encryptor = ::Devise::Encryptors::Sha1
|
||||
|
||||
# The number of times to encrypt password.
|
||||
mattr_accessor :stretches
|
||||
@@stretches = 10
|
||||
@@ -38,6 +43,17 @@ module Devise
|
||||
mattr_accessor :confirm_within
|
||||
@@confirm_within = 0.days
|
||||
|
||||
# Used to define the password encryption algorithm.
|
||||
def self.encryptor=(value)
|
||||
@@encryptor = if value.is_a?(Symbol)
|
||||
::Devise::Encryptors.const_get(value.to_s.classify)
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
mattr_reader :encryptor
|
||||
@@encryptor = ::Devise::Encryptors::Sha1
|
||||
|
||||
# Store scopes mappings.
|
||||
mattr_accessor :mappings
|
||||
@@mappings = {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'digest/sha1'
|
||||
require "digest/sha1"
|
||||
|
||||
module Devise
|
||||
# Implements a way of adding different encryptions.
|
||||
|
||||
@@ -19,11 +19,17 @@ module Devise
|
||||
|
||||
# Creates email, encrypted_password and password_salt.
|
||||
#
|
||||
# == Options
|
||||
# * :null when true, allow columns to be null
|
||||
# * :encryptor The encryptor going to be used, necessary for setting the proper encrypter password length
|
||||
#
|
||||
def authenticatable(options={})
|
||||
null = options[:null] || false
|
||||
string :email, :limit => 100, :null => null
|
||||
string :encrypted_password, :limit => 128, :null => null
|
||||
string :password_salt, :limit => 20, :null => null
|
||||
encryptor = options[:encryptor] || :sha1
|
||||
|
||||
string :email, :null => null, :limit => 100
|
||||
string :encrypted_password, :null => null, :limit => Devise::ENCRYPTORS_LENGTH[encryptor]
|
||||
string :password_salt, :null => null, :limit => 20
|
||||
end
|
||||
|
||||
# Creates confirmation_token, confirmed_at and confirmation_sent_at.
|
||||
|
||||
Reference in New Issue
Block a user