Skip to content

richardbowden/passwordHash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#passwordHash

Codeship Status

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)
}

About

wrapper around golang's SCRYPT module to manage rounds, key lengths, salt in a easy to use package

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages