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 +4 -4
- data/lib/thecore_auth_commons/version.rb +1 -1
- data/lib/thecore_auth_commons.rb +27 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d176940c1499ffd66dd55465578998c0cc33c70518754696ba1b5e359e8af15
|
4
|
+
data.tar.gz: a0ce1ffdded1b4ec50fd5352fa3c4455bf2d05cd3167f9b9115b647a695c6a22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50514966c3705208b4fed5275bbc50ecfdea2cf28e890d9e4ff98366ea5b2b45c9599b6d2e11c3c853dccfa05eef62088e25028ca24722809b66c748b61e37e8
|
7
|
+
data.tar.gz: f94523ce64d76e1e6e663e8dae7f57c1673f781e68087dbad3aee2489d8d30aa06466fc57cecab5dd67b8fd4aac566cb20ec6b21029d26555afec205b5e747dc
|
data/lib/thecore_auth_commons.rb
CHANGED
@@ -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 =
|
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
|