User backend registration

This commit is contained in:
Leons Aleksandrovs
2025-07-05 22:17:14 +03:00
parent 8916f3e394
commit 66ed77e758
6 changed files with 100 additions and 13 deletions
+13
View File
@@ -0,0 +1,13 @@
package utils
import "golang.org/x/crypto/bcrypt"
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return string(bytes), err
}
func CheckPasswordHash(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}
+20
View File
@@ -1 +1,21 @@
package utils
import (
"github.com/gin-gonic/gin"
)
func Success(c *gin.Context, data gin.H) {
// Return success to api
c.JSON(200, gin.H{
"success": true,
"data": data,
})
}
func Error(c *gin.Context, err string, code int) {
// Return error to api
c.JSON(code, gin.H{
"success": false,
"error": err,
})
}