password

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: BSD-3-Clause, BSD-3-Clause Imports: 2 Imported by: 0

README

Package Password

This package has as objective functions for the validation and generation of passwords.

Import

import "github.com/start-codex/utils/password"

Usage

Generate a new password hash
hashed, err := password.HashPassword("my-password", 14)
Create password from hash existing
hashed, err := password.FromHash("$2a$14$2b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6", "my-password")
Get value of password hash string
hash := hashed.String()

Documentation

Index

Constants

View Source
const (
	// ErrPasswordNotMatch is returned when the hashed password does not match the plain-text password.
	ErrPasswordNotMatch = goerror.Error("hashed password does not match plain-text password")
)

Variables

This section is empty.

Functions

func HashPasswordString added in v0.1.0

func HashPasswordString(password string, cost int) string

Types

type Password

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

Password is a struct that holds the hashed password.

func FromHash

func FromHash(hashedPassword string, password string) (Password, error)

FromHash creates a Password from a hashed password and its corresponding plain-text password. It returns an error if the hashed password does not match the plain-text password.

func HashPassword

func HashPassword(password string, cost int) (Password, error)

HashPassword returns a new password from plain password text.

func NoopPassword

func NoopPassword() Password

NewPassword returns a noop password.

func (*Password) IsNil

func (p *Password) IsNil() bool

IsNil returns true if the password is nil or empty.

func (*Password) String

func (p *Password) String() string

String returns the hashed password.

Jump to

Keyboard shortcuts

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