fix: harden auth, config access, and backups

This commit is contained in:
sagitchu
2026-05-13 23:53:06 +08:00
parent ec9fb77eb5
commit 465815cf34
28 changed files with 1376 additions and 97 deletions
+25
View File
@@ -0,0 +1,25 @@
package security
import (
"strings"
"golang.org/x/crypto/bcrypt"
)
func HashPassword(plain string) (string, error) {
hash, err := bcrypt.GenerateFromPassword([]byte(plain), bcrypt.DefaultCost)
if err != nil {
return "", err
}
return string(hash), nil
}
func VerifyPassword(storedHash, plain string) (bool, bool) {
if strings.HasPrefix(storedHash, "$2") {
return bcrypt.CompareHashAndPassword([]byte(storedHash), []byte(plain)) == nil, false
}
if MD5(plain) == storedHash {
return true, true
}
return false, false
}