pswHash

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: BSD-3-Clause Imports: 8 Imported by: 1

README

pswHash

pswHash is a simple Go password hashing module. This module uses the pbkdf2 algorithm along with a sha256 digest. It is a one-way hash.

$ go get github.com/saurabh0719/pswHash

Latest - v1.0.1

Since it follows the exact same schematics the default password hasher in python's Django framework, it can be used to verify passwords when moving to a Go backend but with the same old database from Django.

Read the example.go file in the Example folder of this repository for a clear understanding.


API Reference :

1. Encode
func Encode(password string, salt []byte, iterations int) string

Returns an encoded string in the format of <algorithm>$<iterations>$<salt>$<hash>. Here <algorithm> is pbkdf2_sha256 and the number of iterations is 320000 by default.

2. Decode
func Decode(encoded string) *DecodedHash

Where DecodedHash is a struct of the form :


type DecodedHash struct {
	algorithm  string
	hash       string
	iterations int
	salt       string
}

3. Verify
func Verify(password string, encoded string) bool

Returns true if they match, else false. Uses subtle.ConstantTimeCompare.

4. SafeView
func SafeView(encoded string) *DecodedHash

Returns a struct of type DecodedHash that contains the algorithm, iterations, salt and hash, however, the salt and the hash are masked with *.

// snippet of code from "github.com/saurabh0719/pswHash/pswHash.go"

safeView := &DecodedHash{
		algorithm:  decoded.algorithm,
		iterations: decoded.iterations,
		salt:       maskHash(decoded.salt),
		hash:       maskHash(decoded.hash),
	}

5. Salt
func Salt(length int) ([]byte, error)

Generates and returns a random salt of the given length.


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(password string, salt []byte, iterations int) string

Generate the encoded string for the given password and salt

func Salt

func Salt(length int) ([]byte, error)

Generate a random salt of given length

func Verify

func Verify(password string, encoded string) bool

Verify if the given password generates the same encoded string

Types

type DecodedHash added in v1.0.1

type DecodedHash struct {
	// contains filtered or unexported fields
}

func Decode

func Decode(encoded string) *DecodedHash

Decode the previously Encoded String and return a struct of type DecodedHash

func SafeView

func SafeView(encoded string) *DecodedHash

A safe view of the encoded string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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