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 +}