login-control 0.0.1 → 0.0.3
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 +4 -4
- data/lib/login_control_module.rb +3 -2
- data/lib/login_control_view_helper.rb +13 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7140d5b9a8e9ee22b79f9e2522a09704cdac500ae79ff3f0bd143986d787045c
|
4
|
+
data.tar.gz: e31cca96bd63a22b6b9c6fe9978ab28b09580b676df3575a9d17c5f73f31caa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a949f430c3b55cb22cc85f249a738ef89c1ab66c926a89e7f59cbbd5c68e262682364d9f975e46e833b44060aa8d56f67f68135407c8c99fad9778935d702ea
|
7
|
+
data.tar.gz: 129ccb62c18fbef17a434990b7d14330cee531b339adffe98febe4ffb7c59822f4462d798d98887919f364af9de32d4cb13956ac84671282f77922914f50eea2
|
data/lib/login_control_module.rb
CHANGED
@@ -3,6 +3,7 @@ module LoginControlModule
|
|
3
3
|
# check if captcha is to validate (does not store a cookie)
|
4
4
|
def captcha_validation?(scope: :global, login_name: nil)
|
5
5
|
rec = rc_record(scope, login_name)
|
6
|
+
logger.info "LOGIN-CONTROL => get captcha #{captcha_requested ? '' : 'NOT '}requested from record LoginControl.#{rec.id}" if debug_request_control
|
6
7
|
rec ? rec.validate_captcha : true
|
7
8
|
end
|
8
9
|
|
@@ -13,7 +14,7 @@ module LoginControlModule
|
|
13
14
|
rec.sign_in_success = rec.sign_in_success.to_i + 1
|
14
15
|
rec.attempts = 1
|
15
16
|
rec.save!
|
16
|
-
logger.info "
|
17
|
+
logger.info "LOGIN-CONTROL => #{rec.sign_in_success}. successful request noticed" if debug_request_control
|
17
18
|
end
|
18
19
|
|
19
20
|
# stores cookie, counts up attempts
|
@@ -22,7 +23,7 @@ module LoginControlModule
|
|
22
23
|
rec = find_or_build_rc_record(scope, login_name)
|
23
24
|
rec.attempts = rec.attempts.to_i + 1
|
24
25
|
rec.save!
|
25
|
-
logger.info "
|
26
|
+
logger.info "LOGIN-CONTROL => #{rec.attempts}. failed request noticed" if debug_request_control
|
26
27
|
end
|
27
28
|
|
28
29
|
private
|
@@ -6,35 +6,36 @@ module LoginControlViewHelper
|
|
6
6
|
def captcha_tag?(scope: :global, login_name: nil)
|
7
7
|
debug = (Rails.configuration.x.login_control.debug || !Rails.env.production?)
|
8
8
|
rc_id = cookies.encrypted.permanent[:login_control]
|
9
|
+
captcha_requested = true
|
9
10
|
if request.host == 'localhost'
|
10
|
-
logger.info '
|
11
|
-
false
|
11
|
+
logger.info 'LOGIN-CONTROL => no captcha because of localhost' if debug
|
12
|
+
captcha_requested = false
|
12
13
|
elsif !rc_id.present?
|
13
|
-
logger.info '
|
14
|
-
true
|
14
|
+
logger.info 'LOGIN-CONTROL => captcha because no cookie stored yet' if debug
|
15
|
+
captcha_requested = true
|
15
16
|
else
|
16
|
-
logger.info '
|
17
|
+
logger.info 'LOGIN-CONTROL => cookie found ...' if debug
|
17
18
|
rec = LoginControl.find_by(session_id: rc_id, scope: scope, login_name: login_name)
|
18
19
|
if !rec
|
19
|
-
logger.info '
|
20
|
+
logger.info 'LOGIN-CONTROL => captcha required because no record found(!)' if debug
|
20
21
|
true
|
21
22
|
else
|
22
|
-
logger.info '
|
23
|
-
captcha_requested = true
|
23
|
+
logger.info 'LOGIN-CONTROL => record found ...' if debug
|
24
24
|
|
25
25
|
attempts_allowed = (Rails.configuration.x.login_control.attempts_allowed || 10)
|
26
26
|
retry_after_seconds = (Rails.configuration.x.login_control.retry_after_seconds || 30)
|
27
|
-
logger.info "
|
27
|
+
logger.info "LOGIN-CONTROL => #{rec.attempts.to_i}. attempt (config.x.attempts_allowed: #{attempts_allowed})" if debug
|
28
28
|
|
29
29
|
if rec.attempts.to_i <= attempts_allowed
|
30
30
|
secs = Time.now - rec.updated_at
|
31
31
|
captcha_requested = retry_after_seconds.to_f >= secs
|
32
|
-
logger.info "
|
32
|
+
logger.info "LOGIN-CONTROL => captcha #{captcha_requested ? '' : 'NOT '}requested: config.x.retry_after_seconds(#{retry_after_seconds}) >= secs(#{secs})" if debug
|
33
33
|
end
|
34
34
|
|
35
|
-
rec.update!(validate_captcha: captcha_requested)
|
36
|
-
captcha_requested
|
37
35
|
end
|
36
|
+
rec.update!(validate_captcha: captcha_requested)
|
37
|
+
logger.info "LOGIN-CONTROL => set captcha #{captcha_requested ? '' : 'NOT '}requested to record LoginControl.#{rec.id}" if debug
|
38
|
+
captcha_requested
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: login-control
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Sedlmair
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Based on Login Attempts check if captcha is necessary. It stores a permanent
|
14
14
|
cookie and uses a table for tracking login requests.
|