authlogic 3.8.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/authlogic/acts_as_authentic/base.rb +33 -36
- data/lib/authlogic/acts_as_authentic/email.rb +8 -141
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +17 -10
- data/lib/authlogic/acts_as_authentic/login.rb +14 -165
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +13 -10
- data/lib/authlogic/acts_as_authentic/password.rb +186 -254
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +30 -22
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +19 -18
- data/lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb +53 -0
- data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +83 -0
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +94 -62
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +28 -14
- data/lib/authlogic/config.rb +29 -10
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +43 -13
- data/lib/authlogic/controller_adapters/rack_adapter.rb +11 -5
- data/lib/authlogic/controller_adapters/rails_adapter.rb +11 -29
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +8 -2
- data/lib/authlogic/cookie_credentials.rb +63 -0
- data/lib/authlogic/crypto_providers/bcrypt.rb +24 -18
- data/lib/authlogic/crypto_providers/md5/v2.rb +35 -0
- data/lib/authlogic/crypto_providers/md5.rb +8 -6
- data/lib/authlogic/crypto_providers/scrypt.rb +24 -17
- data/lib/authlogic/crypto_providers/sha1/v2.rb +41 -0
- data/lib/authlogic/crypto_providers/sha1.rb +12 -5
- data/lib/authlogic/crypto_providers/sha256/v2.rb +58 -0
- data/lib/authlogic/crypto_providers/sha256.rb +18 -9
- data/lib/authlogic/crypto_providers/sha512/v2.rb +39 -0
- data/lib/authlogic/crypto_providers/sha512.rb +9 -26
- data/lib/authlogic/crypto_providers.rb +77 -1
- data/lib/authlogic/errors.rb +35 -0
- data/lib/authlogic/i18n/translator.rb +4 -1
- data/lib/authlogic/i18n.rb +29 -20
- data/lib/authlogic/random.rb +12 -28
- data/lib/authlogic/session/base.rb +2087 -33
- data/lib/authlogic/session/magic_column/assigns_last_request_at.rb +46 -0
- data/lib/authlogic/test_case/mock_controller.rb +7 -4
- data/lib/authlogic/test_case/mock_cookie_jar.rb +19 -3
- data/lib/authlogic/test_case/mock_logger.rb +2 -0
- data/lib/authlogic/test_case/mock_request.rb +8 -3
- data/lib/authlogic/test_case/rails_request_adapter.rb +5 -2
- data/lib/authlogic/test_case.rb +74 -2
- data/lib/authlogic/version.rb +22 -0
- data/lib/authlogic.rb +33 -54
- metadata +208 -234
- data/.github/ISSUE_TEMPLATE.md +0 -13
- data/.gitignore +0 -14
- data/.rubocop.yml +0 -33
- data/.rubocop_todo.yml +0 -391
- data/.travis.yml +0 -48
- data/CHANGELOG.md +0 -5
- data/CONTRIBUTING.md +0 -60
- data/Gemfile +0 -5
- data/LICENSE +0 -20
- data/README.md +0 -294
- data/Rakefile +0 -21
- data/authlogic.gemspec +0 -27
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +0 -70
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +0 -32
- data/lib/authlogic/authenticates_many/association.rb +0 -50
- data/lib/authlogic/authenticates_many/base.rb +0 -65
- data/lib/authlogic/crypto_providers/aes256.rb +0 -66
- data/lib/authlogic/crypto_providers/wordpress.rb +0 -43
- data/lib/authlogic/regex.rb +0 -48
- data/lib/authlogic/session/activation.rb +0 -70
- data/lib/authlogic/session/active_record_trickery.rb +0 -61
- data/lib/authlogic/session/brute_force_protection.rb +0 -120
- data/lib/authlogic/session/callbacks.rb +0 -105
- data/lib/authlogic/session/cookies.rb +0 -244
- data/lib/authlogic/session/existence.rb +0 -93
- data/lib/authlogic/session/foundation.rb +0 -55
- data/lib/authlogic/session/http_auth.rb +0 -100
- data/lib/authlogic/session/id.rb +0 -48
- data/lib/authlogic/session/klass.rb +0 -70
- data/lib/authlogic/session/magic_columns.rb +0 -116
- data/lib/authlogic/session/magic_states.rb +0 -76
- data/lib/authlogic/session/params.rb +0 -116
- data/lib/authlogic/session/password.rb +0 -308
- data/lib/authlogic/session/perishable_token.rb +0 -23
- data/lib/authlogic/session/persistence.rb +0 -71
- data/lib/authlogic/session/priority_record.rb +0 -35
- data/lib/authlogic/session/scopes.rb +0 -119
- data/lib/authlogic/session/session.rb +0 -67
- data/lib/authlogic/session/timeout.rb +0 -103
- data/lib/authlogic/session/unauthorized_record.rb +0 -51
- data/lib/authlogic/session/validation.rb +0 -93
- data/test/acts_as_authentic_test/base_test.rb +0 -25
- data/test/acts_as_authentic_test/email_test.rb +0 -240
- data/test/acts_as_authentic_test/logged_in_status_test.rb +0 -62
- data/test/acts_as_authentic_test/login_test.rb +0 -156
- data/test/acts_as_authentic_test/magic_columns_test.rb +0 -27
- data/test/acts_as_authentic_test/password_test.rb +0 -249
- data/test/acts_as_authentic_test/perishable_token_test.rb +0 -90
- data/test/acts_as_authentic_test/persistence_token_test.rb +0 -56
- data/test/acts_as_authentic_test/restful_authentication_test.rb +0 -37
- data/test/acts_as_authentic_test/session_maintenance_test.rb +0 -96
- data/test/acts_as_authentic_test/single_access_test.rb +0 -44
- data/test/authenticates_many_test.rb +0 -31
- data/test/config_test.rb +0 -36
- data/test/crypto_provider_test/aes256_test.rb +0 -14
- data/test/crypto_provider_test/bcrypt_test.rb +0 -14
- data/test/crypto_provider_test/scrypt_test.rb +0 -14
- data/test/crypto_provider_test/sha1_test.rb +0 -23
- data/test/crypto_provider_test/sha256_test.rb +0 -14
- data/test/crypto_provider_test/sha512_test.rb +0 -14
- data/test/fixtures/companies.yml +0 -5
- data/test/fixtures/employees.yml +0 -17
- data/test/fixtures/projects.yml +0 -3
- data/test/fixtures/users.yml +0 -41
- data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.2.x +0 -7
- data/test/gemfiles/Gemfile.rails-5.0.x +0 -6
- data/test/gemfiles/Gemfile.rails-5.1.x +0 -6
- data/test/gemfiles/Gemfile.rails-5.2.x +0 -6
- data/test/i18n/lol.yml +0 -4
- data/test/i18n_test.rb +0 -33
- data/test/libs/affiliate.rb +0 -7
- data/test/libs/company.rb +0 -6
- data/test/libs/employee.rb +0 -7
- data/test/libs/employee_session.rb +0 -2
- data/test/libs/ldaper.rb +0 -3
- data/test/libs/project.rb +0 -3
- data/test/libs/user.rb +0 -7
- data/test/libs/user_session.rb +0 -25
- data/test/random_test.rb +0 -43
- data/test/session_test/activation_test.rb +0 -43
- data/test/session_test/active_record_trickery_test.rb +0 -75
- data/test/session_test/brute_force_protection_test.rb +0 -108
- data/test/session_test/callbacks_test.rb +0 -34
- data/test/session_test/cookies_test.rb +0 -201
- data/test/session_test/credentials_test.rb +0 -0
- data/test/session_test/existence_test.rb +0 -75
- data/test/session_test/foundation_test.rb +0 -6
- data/test/session_test/http_auth_test.rb +0 -56
- data/test/session_test/id_test.rb +0 -17
- data/test/session_test/klass_test.rb +0 -40
- data/test/session_test/magic_columns_test.rb +0 -62
- data/test/session_test/magic_states_test.rb +0 -58
- data/test/session_test/params_test.rb +0 -53
- data/test/session_test/password_test.rb +0 -105
- data/test/session_test/perishability_test.rb +0 -15
- data/test/session_test/persistence_test.rb +0 -32
- data/test/session_test/scopes_test.rb +0 -60
- data/test/session_test/session_test.rb +0 -78
- data/test/session_test/timeout_test.rb +0 -82
- data/test/session_test/unauthorized_record_test.rb +0 -13
- data/test/session_test/validation_test.rb +0 -23
- data/test/test_helper.rb +0 -233
@@ -1,22 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "digest/sha2"
|
2
4
|
|
3
5
|
module Authlogic
|
4
|
-
# The acts_as_authentic method has a crypto_provider option. This allows you
|
5
|
-
#
|
6
|
+
# The acts_as_authentic method has a crypto_provider option. This allows you
|
7
|
+
# to use any type of encryption you like. Just create a class with a class
|
8
|
+
# level encrypt and matches? method. See example below.
|
6
9
|
#
|
7
10
|
# === Example
|
8
11
|
#
|
9
12
|
# class MyAwesomeEncryptionMethod
|
10
13
|
# def self.encrypt(*tokens)
|
11
|
-
# # the tokens passed will be an array of objects, what type of object
|
12
|
-
# # just do what you need to do with them and return a
|
13
|
-
# # for example, you will most likely join all
|
14
|
+
# # the tokens passed will be an array of objects, what type of object
|
15
|
+
# # is irrelevant, just do what you need to do with them and return a
|
16
|
+
# # single encrypted string. for example, you will most likely join all
|
17
|
+
# # of the objects into a single string and then encrypt that string
|
14
18
|
# end
|
15
19
|
#
|
16
20
|
# def self.matches?(crypted, *tokens)
|
17
|
-
# # return true if the crypted string matches the tokens.
|
18
|
-
# #
|
19
|
-
# # encrypt the tokens and make sure it matches the
|
21
|
+
# # return true if the crypted string matches the tokens. Depending on
|
22
|
+
# # your algorithm you might decrypt the string then compare it to the
|
23
|
+
# # token, or you might encrypt the tokens and make sure it matches the
|
24
|
+
# # crypted string, its up to you.
|
20
25
|
# end
|
21
26
|
# end
|
22
27
|
module CryptoProviders
|
@@ -24,6 +29,9 @@ module Authlogic
|
|
24
29
|
#
|
25
30
|
# Uses the Sha256 hash algorithm to encrypt passwords.
|
26
31
|
class Sha256
|
32
|
+
# V2 hashes the digest bytes in repeated stretches instead of hex characters.
|
33
|
+
autoload :V2, File.join(__dir__, "sha256", "v2")
|
34
|
+
|
27
35
|
class << self
|
28
36
|
attr_accessor :join_token
|
29
37
|
|
@@ -40,7 +48,8 @@ module Authlogic
|
|
40
48
|
digest
|
41
49
|
end
|
42
50
|
|
43
|
-
# Does the crypted password match the tokens? Uses the same tokens that
|
51
|
+
# Does the crypted password match the tokens? Uses the same tokens that
|
52
|
+
# were used to encrypt.
|
44
53
|
def matches?(crypted, *tokens)
|
45
54
|
encrypt(*tokens) == crypted
|
46
55
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "digest/sha2"
|
4
|
+
|
5
|
+
module Authlogic
|
6
|
+
module CryptoProviders
|
7
|
+
class Sha512
|
8
|
+
# SHA-512 does not have any practical known attacks against it. However,
|
9
|
+
# there are better choices. We recommend transitioning to a more secure,
|
10
|
+
# adaptive hashing algorithm, like scrypt.
|
11
|
+
class V2
|
12
|
+
class << self
|
13
|
+
attr_accessor :join_token
|
14
|
+
|
15
|
+
# The number of times to loop through the encryption.
|
16
|
+
def stretches
|
17
|
+
@stretches ||= 20
|
18
|
+
end
|
19
|
+
attr_writer :stretches
|
20
|
+
|
21
|
+
# Turns your raw password into a Sha512 hash.
|
22
|
+
def encrypt(*tokens)
|
23
|
+
digest = tokens.flatten.join(join_token)
|
24
|
+
stretches.times do
|
25
|
+
digest = Digest::SHA512.digest(digest)
|
26
|
+
end
|
27
|
+
digest.unpack("H*")[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Does the crypted password match the tokens? Uses the same tokens that
|
31
|
+
# were used to encrypt.
|
32
|
+
def matches?(crypted, *tokens)
|
33
|
+
encrypt(*tokens) == crypted
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,37 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "digest/sha2"
|
2
4
|
|
3
5
|
module Authlogic
|
4
|
-
# The acts_as_authentic method has a crypto_provider option. This allows you
|
5
|
-
# to use any type of encryption you like. Just create a class with a class
|
6
|
-
# level encrypt and matches? method. See example below.
|
7
|
-
#
|
8
|
-
# === Example
|
9
|
-
#
|
10
|
-
# class MyAwesomeEncryptionMethod
|
11
|
-
# def self.encrypt(*tokens)
|
12
|
-
# # The tokens passed will be an array of objects, what type of object
|
13
|
-
# # is irrelevant, just do what you need to do with them and return a
|
14
|
-
# # single encrypted string. For example, you will most likely join all
|
15
|
-
# # of the objects into a single string and then encrypt that string.
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# def self.matches?(crypted, *tokens)
|
19
|
-
# # Return true if the crypted string matches the tokens. Depending on
|
20
|
-
# # your algorithm you might decrypt the string then compare it to the
|
21
|
-
# # token, or you might encrypt the tokens and make sure it matches the
|
22
|
-
# # crypted string, its up to you.
|
23
|
-
# end
|
24
|
-
# end
|
25
6
|
module CryptoProviders
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
7
|
+
# SHA-512 does not have any practical known attacks against it. However,
|
8
|
+
# there are better choices. We recommend transitioning to a more secure,
|
9
|
+
# adaptive hashing algorithm, like scrypt.
|
29
10
|
class Sha512
|
11
|
+
# V2 hashes the digest bytes in repeated stretches instead of hex characters.
|
12
|
+
autoload :V2, File.join(__dir__, "sha512", "v2")
|
13
|
+
|
30
14
|
class << self
|
31
15
|
attr_accessor :join_token
|
32
16
|
|
33
|
-
# The number of times to loop through the encryption.
|
34
|
-
# because that is what restful_authentication defaults to.
|
17
|
+
# The number of times to loop through the encryption.
|
35
18
|
def stretches
|
36
19
|
@stretches ||= 20
|
37
20
|
end
|
@@ -1,11 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
4
|
+
# The acts_as_authentic method has a crypto_provider option. This allows you
|
5
|
+
# to use any type of encryption you like. Just create a class with a class
|
6
|
+
# level encrypt and matches? method. See example below.
|
7
|
+
#
|
8
|
+
# === Example
|
9
|
+
#
|
10
|
+
# class MyAwesomeEncryptionMethod
|
11
|
+
# def self.encrypt(*tokens)
|
12
|
+
# # The tokens passed will be an array of objects, what type of object
|
13
|
+
# # is irrelevant, just do what you need to do with them and return a
|
14
|
+
# # single encrypted string. For example, you will most likely join all
|
15
|
+
# # of the objects into a single string and then encrypt that string.
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# def self.matches?(crypted, *tokens)
|
19
|
+
# # Return true if the crypted string matches the tokens. Depending on
|
20
|
+
# # your algorithm you might decrypt the string then compare it to the
|
21
|
+
# # token, or you might encrypt the tokens and make sure it matches the
|
22
|
+
# # crypted string, its up to you.
|
23
|
+
# end
|
24
|
+
# end
|
2
25
|
module CryptoProviders
|
3
26
|
autoload :MD5, "authlogic/crypto_providers/md5"
|
4
27
|
autoload :Sha1, "authlogic/crypto_providers/sha1"
|
5
28
|
autoload :Sha256, "authlogic/crypto_providers/sha256"
|
6
29
|
autoload :Sha512, "authlogic/crypto_providers/sha512"
|
7
30
|
autoload :BCrypt, "authlogic/crypto_providers/bcrypt"
|
8
|
-
autoload :AES256, "authlogic/crypto_providers/aes256"
|
9
31
|
autoload :SCrypt, "authlogic/crypto_providers/scrypt"
|
32
|
+
|
33
|
+
# Guide users to choose a better crypto provider.
|
34
|
+
class Guidance
|
35
|
+
BUILTIN_PROVIDER_PREFIX = "Authlogic::CryptoProviders::"
|
36
|
+
NONADAPTIVE_ALGORITHM = <<~EOS
|
37
|
+
You have selected %s as your authlogic crypto provider. This algorithm
|
38
|
+
does not have any practical known attacks against it. However, there are
|
39
|
+
better choices.
|
40
|
+
|
41
|
+
Authlogic has no plans yet to deprecate this crypto provider. However,
|
42
|
+
we recommend transitioning to a more secure, adaptive hashing algorithm,
|
43
|
+
like scrypt. Adaptive algorithms are designed to slow down brute force
|
44
|
+
attacks, and over time the iteration count can be increased to make it
|
45
|
+
slower, so it remains resistant to brute-force search attacks even in
|
46
|
+
the face of increasing computation power.
|
47
|
+
|
48
|
+
Use the transition_from_crypto_providers option to make the transition
|
49
|
+
painless for your users.
|
50
|
+
EOS
|
51
|
+
VULNERABLE_ALGORITHM = <<~EOS
|
52
|
+
You have selected %s as your authlogic crypto provider. It is a poor
|
53
|
+
choice because there are known attacks against this algorithm.
|
54
|
+
|
55
|
+
Authlogic has no plans yet to deprecate this crypto provider. However,
|
56
|
+
we recommend transitioning to a secure hashing algorithm. We recommend
|
57
|
+
an adaptive algorithm, like scrypt.
|
58
|
+
|
59
|
+
Use the transition_from_crypto_providers option to make the transition
|
60
|
+
painless for your users.
|
61
|
+
EOS
|
62
|
+
|
63
|
+
def initialize(provider)
|
64
|
+
@provider = provider
|
65
|
+
end
|
66
|
+
|
67
|
+
def impart_wisdom
|
68
|
+
return unless @provider.is_a?(Class)
|
69
|
+
|
70
|
+
# We can only impart wisdom about our own built-in providers.
|
71
|
+
absolute_name = @provider.name
|
72
|
+
return unless absolute_name.start_with?(BUILTIN_PROVIDER_PREFIX)
|
73
|
+
|
74
|
+
# Inspect the string name of the provider, rather than using the
|
75
|
+
# constants in our `when` clauses. If we used the constants, we'd
|
76
|
+
# negate the benefits of the `autoload` above.
|
77
|
+
name = absolute_name.demodulize
|
78
|
+
case name
|
79
|
+
when "MD5", "Sha1"
|
80
|
+
warn(format(VULNERABLE_ALGORITHM, name))
|
81
|
+
when "Sha256", "Sha512"
|
82
|
+
warn(format(NONADAPTIVE_ALGORITHM, name))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
10
86
|
end
|
11
87
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Authlogic
|
4
|
+
# Parent class of all Authlogic errors.
|
5
|
+
class Error < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
# :nodoc:
|
9
|
+
class InvalidCryptoProvider < Error
|
10
|
+
end
|
11
|
+
|
12
|
+
# :nodoc:
|
13
|
+
class NilCryptoProvider < InvalidCryptoProvider
|
14
|
+
def message
|
15
|
+
<<~EOS
|
16
|
+
In version 5, Authlogic used SCrypt by default. As of version 6, there
|
17
|
+
is no default. We still recommend SCrypt. If you previously relied on
|
18
|
+
this default, then, in your User model (or equivalent), please set the
|
19
|
+
following:
|
20
|
+
|
21
|
+
acts_as_authentic do |config|
|
22
|
+
c.crypto_provider = ::Authlogic::CryptoProviders::SCrypt
|
23
|
+
end
|
24
|
+
|
25
|
+
Furthermore, the authlogic gem no longer depends on the scrypt gem. In
|
26
|
+
your Gemfile, please add scrypt.
|
27
|
+
|
28
|
+
gem "scrypt", "~> 3.0"
|
29
|
+
|
30
|
+
We have made this change in Authlogic 6 so that users of other crypto
|
31
|
+
providers no longer need to install the scrypt gem.
|
32
|
+
EOS
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,11 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module I18n
|
5
|
+
# The default translator used by authlogic/i18n.rb
|
3
6
|
class Translator
|
4
7
|
# If the I18n gem is present, calls +I18n.translate+ passing all
|
5
8
|
# arguments, else returns +options[:default]+.
|
6
9
|
def translate(key, options = {})
|
7
10
|
if defined?(::I18n)
|
8
|
-
::I18n.translate key, options
|
11
|
+
::I18n.translate key, **options
|
9
12
|
else
|
10
13
|
options[:default]
|
11
14
|
end
|
data/lib/authlogic/i18n.rb
CHANGED
@@ -1,42 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "authlogic/i18n/translator"
|
2
4
|
|
3
5
|
module Authlogic
|
4
|
-
# This class allows any message in Authlogic to use internationalization. In
|
5
|
-
# versions of Authlogic each message was translated via configuration.
|
6
|
-
# the configuration and cluttered up Authlogic. So all
|
7
|
-
# out into this class. Now all messages pass
|
8
|
-
#
|
9
|
-
#
|
6
|
+
# This class allows any message in Authlogic to use internationalization. In
|
7
|
+
# earlier versions of Authlogic each message was translated via configuration.
|
8
|
+
# This cluttered up the configuration and cluttered up Authlogic. So all
|
9
|
+
# translation has been extracted out into this class. Now all messages pass
|
10
|
+
# through this class, making it much easier to implement in I18n library /
|
11
|
+
# plugin you want. Use this as a layer that sits between Authlogic and
|
12
|
+
# whatever I18n library you want to use.
|
10
13
|
#
|
11
|
-
# By default this uses the rails I18n library, if it exists. If it doesn't
|
12
|
-
# returns the default English message. The Authlogic I18n class
|
13
|
-
# rails I18n class. This is because the arguments are
|
14
|
+
# By default this uses the rails I18n library, if it exists. If it doesn't
|
15
|
+
# exist it just returns the default English message. The Authlogic I18n class
|
16
|
+
# works EXACTLY like the rails I18n class. This is because the arguments are
|
17
|
+
# delegated to this class.
|
14
18
|
#
|
15
19
|
# Here is how all messages are translated internally with Authlogic:
|
16
20
|
#
|
17
21
|
# Authlogic::I18n.t('error_messages.password_invalid', :default => "is invalid")
|
18
22
|
#
|
19
|
-
# If you use a different I18n library just replace the build-in
|
20
|
-
# with your own. For example:
|
23
|
+
# If you use a different I18n library just replace the build-in
|
24
|
+
# I18n::Translator class with your own. For example:
|
21
25
|
#
|
22
26
|
# class MyAuthlogicI18nTranslator
|
23
27
|
# def translate(key, options = {})
|
24
|
-
# # you will have key which will be something like:
|
25
|
-
# #
|
28
|
+
# # you will have key which will be something like:
|
29
|
+
# # "error_messages.password_invalid"
|
30
|
+
# # you will also have options[:default], which will be the default
|
31
|
+
# # English version of the message
|
26
32
|
# # do whatever you want here with the arguments passed to you.
|
27
33
|
# end
|
28
34
|
# end
|
29
35
|
#
|
30
36
|
# Authlogic::I18n.translator = MyAuthlogicI18nTranslator.new
|
31
37
|
#
|
32
|
-
# That it's! Here is a complete list of the keys that are passed. Just define
|
38
|
+
# That it's! Here is a complete list of the keys that are passed. Just define
|
39
|
+
# these however you wish:
|
33
40
|
#
|
34
41
|
# authlogic:
|
35
42
|
# error_messages:
|
36
43
|
# login_blank: can not be blank
|
37
44
|
# login_not_found: is not valid
|
38
45
|
# login_invalid: should use only letters, numbers, spaces, and .-_@+ please.
|
39
|
-
# consecutive_failed_logins_limit_exceeded:
|
46
|
+
# consecutive_failed_logins_limit_exceeded: >
|
47
|
+
# Consecutive failed logins limit exceeded, account is disabled.
|
40
48
|
# email_invalid: should look like an email address.
|
41
49
|
# email_invalid_international: should look like an international email address.
|
42
50
|
# password_blank: can not be blank
|
@@ -46,6 +54,7 @@ module Authlogic
|
|
46
54
|
# not_approved: Your account is not approved
|
47
55
|
# no_authentication_details: You did not provide any details for authentication.
|
48
56
|
# general_credentials_error: Login/Password combination is not valid
|
57
|
+
# session_invalid: Your session is invalid and has the following errors:
|
49
58
|
# models:
|
50
59
|
# user_session: UserSession (or whatever name you are using)
|
51
60
|
# attributes:
|
@@ -79,13 +88,13 @@ module Authlogic
|
|
79
88
|
@@translator = translator
|
80
89
|
end
|
81
90
|
|
82
|
-
# All message translation is passed to this method. The first argument is
|
83
|
-
# for the message. The second is options, see the rails I18n
|
84
|
-
# options used.
|
91
|
+
# All message translation is passed to this method. The first argument is
|
92
|
+
# the key for the message. The second is options, see the rails I18n
|
93
|
+
# library for a list of options used.
|
85
94
|
def translate(key, options = {})
|
86
|
-
translator.translate key, { :
|
95
|
+
translator.translate key, { scope: I18n.scope }.merge(options)
|
87
96
|
end
|
88
|
-
alias
|
97
|
+
alias t translate
|
89
98
|
end
|
90
99
|
end
|
91
100
|
end
|
data/lib/authlogic/random.rb
CHANGED
@@ -1,34 +1,18 @@
|
|
1
|
-
|
2
|
-
# Handles generating random strings. If SecureRandom is installed it will default to
|
3
|
-
# this and use it instead. SecureRandom comes with ActiveSupport. So if you are using
|
4
|
-
# this in a rails app you should have this library.
|
5
|
-
module Random
|
6
|
-
extend self
|
7
|
-
|
8
|
-
SecureRandom = (defined?(::SecureRandom) && ::SecureRandom) ||
|
9
|
-
(defined?(::ActiveSupport::SecureRandom) && ::ActiveSupport::SecureRandom)
|
10
|
-
|
11
|
-
if SecureRandom
|
12
|
-
def hex_token
|
13
|
-
SecureRandom.hex(64)
|
14
|
-
end
|
1
|
+
# frozen_string_literal: true
|
15
2
|
|
16
|
-
|
17
|
-
# use base64url as defined by RFC4648
|
18
|
-
SecureRandom.base64(15).tr('+/=', '').strip.delete("\n")
|
19
|
-
end
|
20
|
-
else
|
21
|
-
def hex_token
|
22
|
-
Authlogic::CryptoProviders::Sha512.encrypt(Time.now.to_s + (1..10).collect { rand.to_s }.join)
|
23
|
-
end
|
3
|
+
require "securerandom"
|
24
4
|
|
25
|
-
|
5
|
+
module Authlogic
|
6
|
+
# Generates random strings using ruby's SecureRandom library.
|
7
|
+
module Random
|
8
|
+
def self.hex_token
|
9
|
+
SecureRandom.hex(64)
|
10
|
+
end
|
26
11
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
12
|
+
# Returns a string in base64url format as defined by RFC-3548 and RFC-4648.
|
13
|
+
# We call this a "friendly" token because it is short and safe for URLs.
|
14
|
+
def self.friendly_token
|
15
|
+
SecureRandom.urlsafe_base64(15)
|
32
16
|
end
|
33
17
|
end
|
34
18
|
end
|