From 671e0ac28ace10103e2cbd07e7e2b2c79ea5b822 Mon Sep 17 00:00:00 2001 From: Geno Date: Thu, 22 Jul 2021 14:50:23 +0200 Subject: [PATCH] web/auth: make hash cost for password configurable - faster testing --- web/auth/lib_password.go | 4 +++- web/auth/models_test.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/web/auth/lib_password.go b/web/auth/lib_password.go index 74a8af2..fab702f 100644 --- a/web/auth/lib_password.go +++ b/web/auth/lib_password.go @@ -4,9 +4,11 @@ import ( "golang.org/x/crypto/bcrypt" ) +var PasswordHashCost = bcrypt.DefaultCost + // HashPassword - create new hash of password func HashPassword(password string) (string, error) { - p, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) + p, err := bcrypt.GenerateFromPassword([]byte(password), PasswordHashCost) if err != nil { return "", err } diff --git a/web/auth/models_test.go b/web/auth/models_test.go index 04ae4ac..167d5fb 100644 --- a/web/auth/models_test.go +++ b/web/auth/models_test.go @@ -5,6 +5,7 @@ import ( gormigrate "github.com/genofire/gormigrate/v2" "github.com/google/uuid" + "golang.org/x/crypto/bcrypt" "gorm.io/gorm" "dev.sum7.eu/genofire/golang-lib/database" @@ -30,6 +31,7 @@ func SetupMigration(db *database.Database) { { ID: "10-data-0008-01-user", Migrate: func(tx *gorm.DB) error { + PasswordHashCost = bcrypt.MinCost user, err := NewUser("admin", "CHANGEME") if err != nil { return err