* fix: code error * feat: opz security * feat: Optimize batch key encryption * feat: Optimize batch test key * feat: Perfect encryption key * docs: failed-to-decrypt * feat: Security alert * feat: Encryption migrate command * fix: migrate command error * feat: Adjust data length * feat: Adjust data length * docs: input text * fix: Deterministic Encryption * feat: Optimize security algorithms * feat: Support KeyHash * fix: Fix migration script field order issue * fix: Fix log export key issue * fix: code style * fix: migrate order offset * fix: Resolve migration script compatibility issues * feat: Adjust Redis cleanup policy * fix: migrate for sqlite * fix: migrate * fix: rm group_key_inx * fix: rm group_key_inx * fix: filter null hash data * docs: log warn * docs: update readme
33 lines
939 B
Go
33 lines
939 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"golang.org/x/crypto/pbkdf2"
|
|
)
|
|
|
|
// ValidatePasswordStrength validates password strength with fixed minimum length of 16 characters
|
|
func ValidatePasswordStrength(password, fieldName string) {
|
|
if len(password) < 16 {
|
|
logrus.Warnf("%s is shorter than 16 characters, consider using a longer password", fieldName)
|
|
}
|
|
|
|
lower := strings.ToLower(password)
|
|
weakPatterns := []string{"password", "sk-123456", "123456", "admin", "secret"}
|
|
|
|
for _, pattern := range weakPatterns {
|
|
if strings.Contains(lower, pattern) {
|
|
logrus.Warnf("%s contains common weak patterns, consider using a stronger password", fieldName)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
// DeriveAESKey derives a 32-byte AES key from password using PBKDF2
|
|
func DeriveAESKey(password string) []byte {
|
|
salt := []byte("gpt-load-encryption-v1")
|
|
return pbkdf2.Key([]byte(password), salt, 100000, 32, sha256.New)
|
|
}
|