/passwd

Go wrapper for hashing and validating password based on Argon2i, Scrypt, Bcrypt.

Primary LanguageGo

passwd

A Golang wrapper for hashing and validating password based on :

Further details :

Requirements

This package require libsodium >= 1.0.10 and currently tested on OSX libsodium via brew install libsodium

Install

go get -u -v github.com/simukti/passwd

Example

  • Argon2i
// default mode is interactive
hashed, _ := passwd.Argon2iPasswordHash([]byte(pwd))

// OR with custom operation
p := passwd.Argon2iPassword{
    Operation: Argon2iOpsLimitModerate,
    Memory:    Argon2iMemLimitModerate,
}

hashed, _ := p.Argon2iHash([]byte(pwd))
  • Scrypt
// default mode is interactive
hashed, _ := passwd.ScryptPasswordHash([]byte(pwd))

// OR with custom operation
p := passwd.ScryptPassword{
    Operation: ScryptOpsLimitSensitive,
    Memory:    ScryptMemLimitSensitive,
}

hashed, _ := p.ScryptHash([]byte(pwd))
  • Bcrypt
// using default cost (12)
hashed, _ := passwd.BcryptPasswordHash([]byte(pwd))

// OR with custom bcrypt cost
p := passwd.BcryptPassword{
    Cost: 10, // default bcrypt cost is 10
}

hashed, ok := p.BcryptHash([]byte(pwd))

Tests

go test -v ./...

$ go test -v ./...
=== RUN   TestScryptHashGenerate
--- PASS: TestScryptHashGenerate (0.05s)
=== RUN   TestScryptHashValidate
--- PASS: TestScryptHashValidate (0.10s)
=== RUN   TestScryptHashValidateModeSensitive
--- PASS: TestScryptHashValidateModeSensitive (6.40s)
=== RUN   TestScryptHashValidateFromOtherApp
--- PASS: TestScryptHashValidateFromOtherApp (0.05s)
=== RUN   TestArgon2iHashGenerate
--- PASS: TestArgon2iHashGenerate (0.14s)
=== RUN   TestArgon2iHashValidate
--- PASS: TestArgon2iHashValidate (0.27s)
=== RUN   TestArgon2iHashValidateModeModerate
--- PASS: TestArgon2iHashValidateModeModerate (1.71s)
=== RUN   TestArgon2iHashValidateModeSensitive
--- PASS: TestArgon2iHashValidateModeSensitive (9.49s)
=== RUN   TestArgon2iHashValidateFromOtherApp
--- PASS: TestArgon2iHashValidateFromOtherApp (0.14s)
=== RUN   TestBcryptHashGenerate
--- PASS: TestBcryptHashGenerate (0.33s)
=== RUN   TestBcryptHashValidate
--- PASS: TestBcryptHashValidate (0.67s)
=== RUN   TestBcryptHashValidateFromOtherApp
--- PASS: TestBcryptHashValidateFromOtherApp (0.66s)
=== RUN   TestBcryptWithCustomCost
--- PASS: TestBcryptWithCustomCost (0.24s)
PASS
ok  	github.com/simukti/passwd	20.257s

License

MIT