Merge branch 'master' of github.com:muety/wakapi

This commit is contained in:
Ferdinand Mütsch
2025-11-19 09:19:19 +01:00
2 changed files with 11 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ func init() {
const name = "20250907-add_user_heartbeats_range_view"
f := migrationFunc{
name: name,
background: true,
background: false,
f: func(db *gorm.DB, cfg *config.Config) error {
if hasRun(name, db) {
return nil

View File

@@ -3,11 +3,14 @@ package utils
import (
"encoding/base64"
"errors"
"github.com/alexedwards/argon2id"
"golang.org/x/crypto/bcrypt"
"net/http"
"regexp"
"runtime"
"strings"
"github.com/alexedwards/argon2id"
"github.com/duke-git/lancet/v2/mathutil"
"golang.org/x/crypto/bcrypt"
)
var md5Regex = regexp.MustCompile(`^[a-f0-9]{32}$`)
@@ -79,7 +82,11 @@ func CompareArgon2Id(hashed, plain, pepper string) bool {
func HashArgon2Id(plain, pepper string) (string, error) {
plainPepperedPassword := strings.TrimSpace(plain) + pepper
hash, err := argon2id.CreateHash(plainPepperedPassword, argon2id.DefaultParams)
params := *argon2id.DefaultParams
if params.Parallelism == 0 { // https://github.com/muety/wakapi/issues/866
params.Parallelism = uint8(mathutil.Min[int](runtime.NumCPU(), 255))
}
hash, err := argon2id.CreateHash(plainPepperedPassword, &params)
if err == nil {
return hash, nil
}