Реализован production-hardening по fix1: env/reconfigure, IPv4-only, TLS, secrets, firewall, docs

This commit is contained in:
2026-04-26 07:27:06 +05:00
parent 2b4a45ad23
commit 3fccd5c442
109 changed files with 1773 additions and 569 deletions
+26
View File
@@ -2,7 +2,11 @@ package util
import (
"crypto/sha256"
"errors"
"fmt"
"strings"
"golang.org/x/crypto/bcrypt"
)
func SHA224String(password string) string {
@@ -16,3 +20,25 @@ func SHA224String(password string) string {
return str
}
func HashPassword(password string) (string, error) {
if len(strings.TrimSpace(password)) < 6 {
return "", errors.New("password too short")
}
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
return "", err
}
return string(hash), nil
}
func IsBcryptHash(hash string) bool {
return strings.HasPrefix(hash, "$2a$") || strings.HasPrefix(hash, "$2b$") || strings.HasPrefix(hash, "$2y$")
}
func VerifyPassword(password string, storedHash string) (ok bool, legacy bool) {
if IsBcryptHash(storedHash) {
err := bcrypt.CompareHashAndPassword([]byte(storedHash), []byte(password))
return err == nil, false
}
return SHA224String(password) == storedHash, true
}