Skip to content

Commit

Permalink
Merge pull request ManageIQ#1052 from bdunne/database_password_integer
Browse files Browse the repository at this point in the history
Only return passwords that include letters.
  • Loading branch information
Fryguy authored Feb 8, 2024
2 parents 16fee3b + 57227fd commit 668e699
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/rand"
"encoding/base64"
"encoding/hex"
"regexp"
)

func randomBytes(n int) []byte {
Expand All @@ -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
}
}
}

0 comments on commit 668e699

Please sign in to comment.