aspnetpass

package module
v0.0.0-...-9d2d364 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2018 License: MIT Imports: 11 Imported by: 0

README

aspnet-pass

This is an implementation of .Net PasswordHasher class in Golang.

Godoc Build Status Coverage Status

Documentation

Index

Constants

View Source
const (
	AlgoSha1   = "sha1"
	AlgoSha256 = "sha256"
	AlgoSha512 = "sha512"
)

List of supported algorithms

Variables

View Source
var (
	ErrBadSize      = errors.New("aspnetpass: bad size")
	ErrBadSaltLen   = errors.New("aspnetpass: bad salt length")
	ErrBadKeyLen    = errors.New("aspnetpass: bad key length")
	ErrBadVersion   = errors.New("aspnetpass: bad version")
	ErrBadAlgorithm = errors.New("aspnetpass: bad algorithm")
	ErrBadIteration = errors.New("aspnetpass: bad iteration")
)

List of errors

Functions

func Decrypt

func Decrypt(hstr string) (ver string, key, salt []byte, iter int, alg string, err error)

Decrypt decrypts .Net password hash string

func Hash

func Hash(pass string) (string, error)

Hash hashes the given pass using the DefaultHasher

func Verify

func Verify(pass, hash string) (bool, error)

Verify verifies if a password matches to a .Net password hash string

Types

type Hasher

type Hasher interface {
	Hash(string) (string, error)
}

Hasher is the interface that wraps the basic Hash method

var DefaultHasher Hasher = &hasherV3{
	sg:   rand.New(rand.NewSource(time.Now().UnixNano())),
	iter: 10000,
	slen: 16,
	klen: 32,
	algo: AlgoSha256,
}

DefaultHasher is the .Net password hasher v3 with default configuration

func NewHasherV2

func NewHasherV2(sg SaltGenerator) (Hasher, error)

NewHasherV2 returns a new HasherV2 instance

func NewHasherV3

func NewHasherV3(iter, saltLen, keyLen int, algo string, sg SaltGenerator) (Hasher, error)

NewHasherV3 returns a new HasherV3 instance with salt length of saltLen bytes, minimum 16 byte key length of keyLen bytes, minimum 32 byte algo should be one of the sha1, sha256 or sha512

type SaltGenerator

type SaltGenerator interface {
	Read(p []byte) (int, error)
}

SaltGenerator is the interface that generates salt

Read generates len(p) bytes it should return the len(p) and a nil error otherwise 0, error

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL