User backend registration
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user