# README
#passwordHash
An easy to use wrapper around https://godoc.org/golang.org/x/crypto/scrypt
Extracted from a bigger application so this can be used by others if it helps.
This wrapper sets sensible defaults for use with the scrypt package, it also generates a cryptographically secure pseudorandom number for a per password salt using crypto/rand.
#defaults
Name | Setting | Description |
---|---|---|
defaultByteLength | 64 | used salt and password hash length |
defaultR | 16 | number of rounds |
defaultN | 16384 | CPU / Memory cost, needs to be power of 2 |
#Usage
package main
import (
"fmt"
"github.com/richardbowden/passwordHash"
)
func main() {
mypass := "mypassword"
fmt.Println("Test password=", mypass)
hashToStore, _ := passwordHash.HashWithDefaults(mypass, mypass)
valid := passwordHash.Validate(mypass, mypass, hashToStore)
fmt.Printf("Password is valid=%v\n", valid)
fmt.Println("Testing invalid password=no against passowrd=mypassword")
valid = passwordHash.Validate("no", hashToStore)
fmt.Printf("Password is not valid=%v\n", valid)
}
# Packages
No description provided by the author
# Functions
GenerateSalt takes a byte size as an int, returns a secure random stirng tothe size of byteSize.
Hash hashes p1 (password) using r (rounds), n (costParam) anda securely generated salt (see GenerateSalt func).
HashWithDefaults is the same as Hash, but uses the default settings
default r (rounds) = 16default N (cpu/ memory cost) = 16386default h (hashByteSize) = 64default s (saltByteSize) = 64
returns a string as: r:n:keyLength:salt:hashedPassword.
Validate compares password against stored hash.
# Constants
DefaultKeyByteLength is the default length (bytes) of the hash that will be generated.
DefaultN is a CPU/memory cost parameter which must be a power of two greater than 1.
DefaultR is the number of rounds of hashing used to generated a hashed password.
DefaultSaltByteLength is the default length (bytes) of a generated secure random salt.
# Structs
DefaultPasswordHasher impliments the PasswordHasher interface which uses passwordHash.
# Interfaces
PasswordHasher is an interface that describes two basic functions that can be used to perform a password encode and validate.