password

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package password provides functions for hashing and verifying passwords.

Example usage: hashedPassword, err := password.Hash("mysecretpassword") isValid, err := password.Matches("mysecretpassword", hashedPassword)

Index

Constants

View Source
const (
	// MinCost is the minimum bcrypt cost factor
	MinCost = bcrypt.MinCost // 4
	// MaxCost is the maximum bcrypt cost factor
	MaxCost = bcrypt.MaxCost // 31
	// DefaultCost is the default cost factor used if not specified
	// or if specified cost is invalid
	DefaultCost = 12
	// RecommendedMinCost is the recommended minimum cost for production use
	RecommendedMinCost = 10
)

Variables

View Source
var (
	// ErrEmptyPassword indicates that an empty password was provided
	ErrEmptyPassword = errors.New("password cannot be empty")
	// ErrEmptyHash indicates that an empty hash was provided for verification
	ErrEmptyHash = errors.New("hash cannot be empty")
)
View Source
var CommonPasswords = []string{}/* 10000 elements not displayed */

CommonPasswords list is from https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10k-most-common.txt

Functions

func Cost

func Cost(hashedPassword string) (int, error)

Cost returns the cost factor used to create the given hash Returns an error if the hash is invalid or empty

func Hash

func Hash(plaintext string, opts ...Option) (string, error)

Hash creates a password hash with the given options If no options are provided, DefaultCost will be used Returns ErrEmptyPassword if the password is empty

func Verify

func Verify(plaintext, hashedPassword string) (bool, error)

Verify compares a plaintext password with a hashed password Returns true if they match, false if they don't. Returns an error if there's a system error or if inputs are invalid

Types

type Option

type Option func(*config)

Option defines a function that can modify the config

func WithCost

func WithCost(cost int) Option

WithCost sets the bcrypt cost parameter If cost is outside valid range (MinCost to MaxCost), DefaultCost will be used instead

Jump to

Keyboard shortcuts

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