52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package argon2_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"euphoria-laxis.fr/go-packages/argon2/v1.1.0"
|
|
)
|
|
|
|
func TestDecoder(t *testing.T) {
|
|
opts = []argon2.OptFunc{
|
|
argon2.SetMemory(32 * 1024), // 32 bits
|
|
argon2.SetParallelism(4), // 4 concurrent actions
|
|
argon2.SetKeyLength(32), // key length
|
|
argon2.SetSaltLength(32), // salt length
|
|
argon2.SetIterations(4), // 4 iterations, should be fast since there's 4 concurrent actions
|
|
}
|
|
e, _ := argon2.NewEncoder(opts...)
|
|
var err error
|
|
randomString, err = e.RandomString(32)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
hashedString, err = e.HashString(randomString)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
d := argon2.NewDecoder()
|
|
var match bool
|
|
match, err = d.CompareStringToHash(randomString, hashedString)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !match {
|
|
t.Log("passwords comparison failed")
|
|
t.Log("passwords should match")
|
|
t.Fail()
|
|
}
|
|
randomString, err = e.RandomString(32)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
match, err = d.CompareStringToHash(randomString, hashedString)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if match {
|
|
t.Log("passwords comparison failed")
|
|
t.Log("passwords shouldn't match")
|
|
t.Fail()
|
|
}
|
|
}
|