migrate from github

This commit is contained in:
2026-07-15 22:42:31 +08:00
commit 3ad559f05e
262 changed files with 21637 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
package utils
import (
"github.com/XingfenD/yoresee_doc/internal/config"
"golang.org/x/crypto/bcrypt"
)
func HashPassword(password string) (string, error) {
cost := bcrypt.DefaultCost
if config.GlobalConfig != nil {
c := config.GlobalConfig.Backend.Security.PasswordHashCost
if c >= bcrypt.MinCost && c <= bcrypt.MaxCost {
cost = c
}
}
bytes, err := bcrypt.GenerateFromPassword([]byte(password), cost)
return string(bytes), err
}
func CheckPassword(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}