web/auth: make hash cost for password configurable - faster testing
continuous-integration/drone the build is pending Details

This commit is contained in:
Geno 2021-07-22 14:50:23 +02:00
parent 689bb03277
commit 671e0ac28a
2 changed files with 5 additions and 1 deletions

View File

@ -4,9 +4,11 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )
var PasswordHashCost = bcrypt.DefaultCost
// HashPassword - create new hash of password // HashPassword - create new hash of password
func HashPassword(password string) (string, error) { func HashPassword(password string) (string, error) {
p, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) p, err := bcrypt.GenerateFromPassword([]byte(password), PasswordHashCost)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -5,6 +5,7 @@ import (
gormigrate "github.com/genofire/gormigrate/v2" gormigrate "github.com/genofire/gormigrate/v2"
"github.com/google/uuid" "github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm" "gorm.io/gorm"
"dev.sum7.eu/genofire/golang-lib/database" "dev.sum7.eu/genofire/golang-lib/database"
@ -30,6 +31,7 @@ func SetupMigration(db *database.Database) {
{ {
ID: "10-data-0008-01-user", ID: "10-data-0008-01-user",
Migrate: func(tx *gorm.DB) error { Migrate: func(tx *gorm.DB) error {
PasswordHashCost = bcrypt.MinCost
user, err := NewUser("admin", "CHANGEME") user, err := NewUser("admin", "CHANGEME")
if err != nil { if err != nil {
return err return err