login-control 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6836209796584aad1dbcf76ec600cd30e1612929c827a50fce7e314f0855076b
4
- data.tar.gz: 989f4356315dc1ad769f3ed4ea3a3b14afd89af6538df5a243e1ac2856bcf310
3
+ metadata.gz: 65870b8b7ac15bff2ace601e0acbe5ae5038a00bdebc73f9d4aa6ed1c0650a15
4
+ data.tar.gz: 2696d809010c5296e8dcf2151632bbbc58eb2815d10afa756a02d561bb8342c3
5
5
  SHA512:
6
- metadata.gz: b7055e036d046c5568cdbe7adce1f90fad68a948656454aa5fe6b7a649f728c630cf28b70df01f4c209b6cc31616b9fa68a61e666804b15941a718ec6fb2520e
7
- data.tar.gz: bc180a24f2b6673a28a35e11ceeb795f5a347f1d6186fe7f8c0a8935d53effae209e18ca0370dafe7be154be71144316b246af19f92219780f2fa3810fa38727
6
+ metadata.gz: b92e08058e2e2280449e55e47bab6cc8178203d7833ec475f54e47e25e2fb69a5162226ea70d9d7e9881620a90914daed60c7a0c1a591799af269942426badf9
7
+ data.tar.gz: 64aa7205d51924951e6fe98f5d2c084648e88b7bfa5519c34c4344f12d472b388696e65c7bed49678df19cd2522e434f204c54a912ef47b63cad588a6b0020e3
@@ -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
 
@@ -11,6 +12,7 @@ module LoginControlModule
11
12
  def notice_successful_request(scope: :global, login_name: nil)
12
13
  rec = find_or_build_rc_record(scope, login_name)
13
14
  rec.sign_in_success = rec.sign_in_success.to_i + 1
15
+ rec.last_attempt = DateTime.now
14
16
  rec.attempts = 1
15
17
  rec.save!
16
18
  logger.info "LOGIN-CONTROL => #{rec.sign_in_success}. successful request noticed" if debug_request_control
@@ -21,6 +23,7 @@ module LoginControlModule
21
23
  def notice_request_attempt(scope: :global, login_name: nil)
22
24
  rec = find_or_build_rc_record(scope, login_name)
23
25
  rec.attempts = rec.attempts.to_i + 1
26
+ rec.last_attempt = DateTime.now
24
27
  rec.save!
25
28
  logger.info "LOGIN-CONTROL => #{rec.attempts}. failed request noticed" if debug_request_control
26
29
  end
@@ -6,12 +6,13 @@ 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
11
  logger.info 'LOGIN-CONTROL => no captcha because of localhost' if debug
11
- false
12
+ captcha_requested = false
12
13
  elsif !rc_id.present?
13
14
  logger.info 'LOGIN-CONTROL => captcha because no cookie stored yet' if debug
14
- true
15
+ captcha_requested = true
15
16
  else
16
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)
@@ -20,21 +21,21 @@ module LoginControlViewHelper
20
21
  true
21
22
  else
22
23
  logger.info 'LOGIN-CONTROL => record found ...' if debug
23
- captcha_requested = true
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
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
- secs = Time.now - rec.updated_at
30
+ secs = Time.now - rec.last_attempt
31
31
  captcha_requested = retry_after_seconds.to_f >= secs
32
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.2
4
+ version: 0.0.4
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-07 00:00:00.000000000 Z
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.