feat(user): argon2id password hashing helpers

This commit is contained in:
2026-04-28 15:46:23 +08:00
parent 46fda4f594
commit da316725fc
4 changed files with 117 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
package user
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestHashAndVerifyPassword(t *testing.T) {
hash, err := HashPassword("hello-world-12345")
require.NoError(t, err)
require.NotEmpty(t, hash)
ok, err := VerifyPassword("hello-world-12345", hash)
require.NoError(t, err)
require.True(t, ok)
bad, err := VerifyPassword("wrong", hash)
require.NoError(t, err)
require.False(t, bad)
}
func TestHashPassword_RejectsTooShort(t *testing.T) {
_, err := HashPassword("short")
require.Error(t, err)
}