thecore_auth_commons 3.4.0 → 3.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5ff5d59febf329c917067988bc9a854f77222f310d07a34b98adbf500b92abd
4
- data.tar.gz: ece767087f4e4bde62d0500c8e7b9840b0482043401d3df2052009b32cdfe639
3
+ metadata.gz: 2d176940c1499ffd66dd55465578998c0cc33c70518754696ba1b5e359e8af15
4
+ data.tar.gz: a0ce1ffdded1b4ec50fd5352fa3c4455bf2d05cd3167f9b9115b647a695c6a22
5
5
  SHA512:
6
- metadata.gz: fc4901ac970bc086ae02863f9d82bfb72028055193d3bb6190d0b2396e8c86adf261b8ac6eb101b5de971729f734da6b8a1692454654c9731f3c868d07aed9d9
7
- data.tar.gz: 7cf606e7d94bf1ef8c404b7bf859130c9d33c06a4d20cc4228dad1d1f035db5b1a99746504a5d92280fbdf818cfe13716ca2c99a21535445d712912063653705
6
+ metadata.gz: 50514966c3705208b4fed5275bbc50ecfdea2cf28e890d9e4ff98366ea5b2b45c9599b6d2e11c3c853dccfa05eef62088e25028ca24722809b66c748b61e37e8
7
+ data.tar.gz: f94523ce64d76e1e6e663e8dae7f57c1673f781e68087dbad3aee2489d8d30aa06466fc57cecab5dd67b8fd4aac566cb20ec6b21029d26555afec205b5e747dc
@@ -1,3 +1,3 @@
1
1
  module ThecoreAuthCommons
2
- VERSION = "3.4.0".freeze
2
+ VERSION = "3.4.1".freeze
3
3
  end
@@ -58,7 +58,7 @@ module ThecoreAuthCommons
58
58
  user.auth_source = "ldap #{server_id}"
59
59
 
60
60
  # Password don't need to be changed, just created, otherwise it will invalidate the current user session if it's logged in
61
- user.password = user.password_confirmation = Devise.friendly_token[0, 20] if user.new_record?
61
+ user.password = user.password_confirmation = ThecoreAuthCommons.generate_secure_password if user.new_record?
62
62
 
63
63
  # Eventuale mapping LDAP -> campi User
64
64
  user.name = entry[:givenname]&.first if user.respond_to?(:name)
@@ -79,4 +79,30 @@ module ThecoreAuthCommons
79
79
  puts "Cannot save user #{email} with errors: #{user.errors.full_messages.join(", ")}" unless user.save # if user.new_record? || user.changed? || user.roles_changed?
80
80
  user
81
81
  end
82
+
83
+ def self.generate_secure_password(length = 20)
84
+ raise ArgumentError, 'Length must be at least 4' if length < 4
85
+
86
+ # Caratteri da cui attingere
87
+ lowercase = ('a'..'z').to_a
88
+ uppercase = ('A'..'Z').to_a
89
+ numbers = ('0'..'9').to_a
90
+ symbols = ['!', '@', '#', '$', '%', '&', '*', '?', '-', '_', '+', '=']
91
+
92
+ # Obbliga almeno un carattere da ogni gruppo
93
+ password = [
94
+ lowercase.sample,
95
+ uppercase.sample,
96
+ numbers.sample,
97
+ symbols.sample
98
+ ]
99
+
100
+ # Caratteri restanti scelti a caso tra tutti
101
+ all_characters = lowercase + uppercase + numbers + symbols
102
+ (length - 4).times { password << all_characters.sample }
103
+
104
+ # Mischia per evitare ordine prevedibile
105
+ password.shuffle.join
106
+ end
107
+
82
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thecore_auth_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni