From 743ce2ce751d476b3cdf3374749df21db3069312 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Thu, 8 Feb 2024 10:35:25 -0500 Subject: [PATCH] Merge pull request #1052 from bdunne/database_password_integer Only return passwords that include letters. (cherry picked from commit 668e69924bd86df71c135251af091fe87c8d84ca) --- .../v1alpha1/helpers/miq-components/generators.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/manageiq-operator/api/v1alpha1/helpers/miq-components/generators.go b/manageiq-operator/api/v1alpha1/helpers/miq-components/generators.go index 443cb7863..9a15b0849 100644 --- a/manageiq-operator/api/v1alpha1/helpers/miq-components/generators.go +++ b/manageiq-operator/api/v1alpha1/helpers/miq-components/generators.go @@ -4,6 +4,7 @@ import ( "crypto/rand" "encoding/base64" "encoding/hex" + "regexp" ) func randomBytes(n int) []byte { @@ -20,6 +21,13 @@ func generateEncryptionKey() string { } func generatePassword() string { - buf := randomBytes(8) - return hex.EncodeToString(buf) + for { + buf := randomBytes(8) + password := hex.EncodeToString(buf) + if match, err := regexp.MatchString(`\D+`, password); err == nil && match { + // Only return if a letter is included. + // Password decryption can fail if the database password is all numbers because ruby will read it as an integer instead of a string. + return password + } + } }