From 39413b9a9ccb164209e89f70045461c5a51830ed Mon Sep 17 00:00:00 2001 From: hupeh Date: Mon, 2 Jan 2023 12:40:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/fns.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 app/fns.go diff --git a/app/fns.go b/app/fns.go new file mode 100644 index 0000000..a420c4e --- /dev/null +++ b/app/fns.go @@ -0,0 +1,13 @@ +package app + +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 +}