password

package
v0.0.0-...-7bf004b Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinLength is the minimum number of characters a password MUST contain.
	MinLength = 10
	// MaxLength is the maximum number of characters a password MUST contain.
	MaxLength = 64
)

Variables

View Source
var (
	// ErrPasswordWeak indicates the password does not meet our rules.
	ErrPasswordWeak = merry.
					New("password does not meet the requirements and is considered weak").
					WithUserMessage("Password does not meet the requirements and is considered too weak.")
	// ErrPasswordLength indicates the password is not within the min and max
	// length requirement.
	ErrPasswordLength = merry.
						WithMessage(ErrPasswordWeak, fmt.Sprintf("password must be %d-%d characters long", MinLength, MaxLength)).
						WithUserMessage(fmt.Sprintf("Password must be %d-%d characters long.", MinLength, MaxLength))
	// ErrPasswordContainsName indicates the password is not allowed because it
	// contains part or all of their name or username.
	ErrPasswordContainsName = merry.
							WithMessage(ErrPasswordWeak, "password cannot contain the first, last, and/or username").
							WithUserMessage("Password cannot contain your any part of your name or username.")
)

Functions

func CheckPasswordRules

func CheckPasswordRules(username string, firstName string, lastName string,
	password string) error

CheckPasswordRules returns nil if the password meets all of the requirements. Otherwise, it returns an error describing which rule it currently violates.

Rules:

  • Must be at between MinLength and MaxLength

TODO: Check against a list of common passwords - JZ TODO: Check this isn't equal to their current password? - JZ

func Hash

func Hash(password string) (string, error)

Hash take a plaintext password and returns a securely hashed version.

Currently uses bcrypt

Use this instead of a specific hashing algorithm so we can change which algorithm is used between versions.

func Valid

func Valid(password string, hashedPassword string) (valid bool,
	insecure bool, err error)

Valid returns true if the given password matches the password hash.

If the password is valid, it will also return false if it is not using a secure hashing algorithm and needs updated (currently bcrypt).

Types

This section is empty.

Jump to

Keyboard shortcuts

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