fix: update user plan and rearrange structur project

This commit is contained in:
ericprd
2025-03-08 22:46:05 +08:00
parent a47b7b7d3d
commit 13c976dcbf
54 changed files with 508 additions and 263 deletions
+32
View File
@@ -0,0 +1,32 @@
package utils
import (
"fmt"
"github.com/golang-jwt/jwt/v5"
"golang.org/x/crypto/bcrypt"
)
func VerifyToken(signature string) jwt.Keyfunc {
return func(token *jwt.Token) (any, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
return []byte(signature), nil
}
}
func HashPassword(password string) (string, error) {
// Hashing the password with a cost of 14 (default)
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
return "", err
}
return string(hash), nil
}
func ComparePassword(storedPassword, inputPassword string) bool {
err := bcrypt.CompareHashAndPassword([]byte(storedPassword), []byte(inputPassword))
return err == nil
}