mirror of
https://github.com/muety/wakapi.git
synced 2025-12-05 22:20:24 -08:00
Merge branch 'master' of github.com:muety/wakapi
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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, ¶ms)
|
||||
if err == nil {
|
||||
return hash, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user