diff options
Diffstat (limited to 'pkg/utils.go')
-rw-r--r-- | pkg/utils.go | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/pkg/utils.go b/pkg/utils.go deleted file mode 100644 index 9246854..0000000 --- a/pkg/utils.go +++ /dev/null @@ -1,35 +0,0 @@ -package utils - -import ( - "encoding/json" - "net/http" - - "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 -} - -// Set a JSON response with status code 400 -func JsonError(w *http.ResponseWriter, error string) { - payloadMap := map[string]string{"error": error} - - (*w).Header().Set("Content-Type", "application/json") - (*w).WriteHeader(http.StatusBadRequest) - - payload, err := json.Marshal(payloadMap) - - if err != nil { - (*w).WriteHeader(http.StatusBadGateway) - (*w).Write([]byte(err.Error())) - } else { - (*w).Write(payload) - } -} |