75f3dd141c
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CI and Release / lint-frontend (push) Has been cancelled
CI and Release / dockerfile-scan (push) Has been cancelled
CI and Release / test-frontend (push) Has been cancelled
CI and Release / lint-verification-agent (push) Has been cancelled
CI and Release / test-verification-agent (push) Has been cancelled
CI and Release / e2e-verification-agent (push) Has been cancelled
CI and Release / test-backend (push) Has been cancelled
CI and Release / build-dev-image (push) Has been cancelled
CI and Release / push-dev-image (push) Has been cancelled
CI and Release / build-image (push) Has been cancelled
CI and Release / build-verification-image (push) Has been cancelled
CI and Release / determine-version (push) Has been cancelled
CI and Release / push-image (push) Has been cancelled
CI and Release / push-verification-image (12) (push) Has been cancelled
CI and Release / lint-backend (push) Has been cancelled
CI and Release / push-verification-image (17) (push) Has been cancelled
CI and Release / push-verification-image (18) (push) Has been cancelled
CI and Release / release (push) Has been cancelled
CI and Release / publish-helm-chart (push) Has been cancelled
CI and Release / push-verification-image (13) (push) Has been cancelled
CI and Release / push-verification-image (14) (push) Has been cancelled
CI and Release / push-verification-image (15) (push) Has been cancelled
CI and Release / push-verification-image (16) (push) Has been cancelled
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package encryption
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"math/big"
|
|
)
|
|
|
|
// GenerateComplexPassword creates a password that meets common cloud provider requirements:
|
|
// - At least one lowercase letter
|
|
// - At least one uppercase letter
|
|
// - At least one digit
|
|
// - At least one special character
|
|
// - 24 characters for security
|
|
func GenerateComplexPassword() string {
|
|
const (
|
|
lowercase = "abcdefghijklmnopqrstuvwxyz"
|
|
uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
digits = "0123456789"
|
|
special = "!@#$%^&*()-_=+"
|
|
all = lowercase + uppercase + digits + special
|
|
)
|
|
|
|
password := make([]byte, 24)
|
|
|
|
// Ensure at least one character from each required set
|
|
password[0] = randomChar(lowercase)
|
|
password[1] = randomChar(uppercase)
|
|
password[2] = randomChar(digits)
|
|
password[3] = randomChar(special)
|
|
|
|
// Fill the rest with random characters from all sets
|
|
for i := 4; i < len(password); i++ {
|
|
password[i] = randomChar(all)
|
|
}
|
|
|
|
// Shuffle the password to avoid predictable positions
|
|
shuffleBytes(password)
|
|
|
|
return string(password)
|
|
}
|
|
|
|
func randomChar(charset string) byte {
|
|
n, err := rand.Int(rand.Reader, big.NewInt(int64(len(charset))))
|
|
if err != nil {
|
|
return charset[0]
|
|
}
|
|
return charset[n.Int64()]
|
|
}
|
|
|
|
func shuffleBytes(b []byte) {
|
|
for i := len(b) - 1; i > 0; i-- {
|
|
n, err := rand.Int(rand.Reader, big.NewInt(int64(i+1)))
|
|
if err != nil {
|
|
continue
|
|
}
|
|
j := n.Int64()
|
|
b[i], b[j] = b[j], b[i]
|
|
}
|
|
}
|