reset

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Documentation License Go Report Card

passwd/reset

stateless password reset helpers function

Description

the passwd package is mainly about creating password to be stored offline. subpackage passwd/reset allows coders to create a stateless password reset in their app.

the idea is simple, provide the following:

  • generate a password reset codes
  • the code expires after time.Duration
  • the reset code should be used only ONCE after the password reset.

How to Use the package

**Prerequisite:

You are already hashing / storing your password properly, with passwd package or another package.

Create Password Reset Code

Commonly password hashing includes hashing parameters in order to provide interoperability.

if no interoperability is needed (outside your authentication needs) and to make things slightly more annoying for a regular attacker, you might "mask" your parameters (instead of embedding them in the resulting hash).

Validate the reset code

Public parameters will embbed the derivation parameters in the resulting hash. This allows you to simply use the passwd.Compare() function against a hash without the need of a profile object.

Examples

Documentation

Index

Constants

View Source
const (
	// DefaultExpiration defines the proposed expiration TTL of the reset
	// codes.
	DefaultExpiration = 10 * time.Minute
	// ExpiryOneHour defines a one hour duration for expiration.
	ExpiryOneHour = 1 * time.Hour
	// ExpiryOneDay defines a one day duration for the reset code
	// expiration.
	ExpiryOneDay = 24 * time.Hour
)

Variables

This section is empty.

Functions

func NewCode

func NewCode(hashed, userdata []byte, d time.Duration) (string, error)

NewCode creates a new packed reset.Code embedding userdata and valid for d time.Duration using hashed password.

func VerifyCode

func VerifyCode(hashed []byte, code string) ([]byte, error)

VerifyCode verify the provided code using hashed password and returns the embedded userdata.

Types

type Code

type Code struct {
	Time     int64
	Userdata []byte // store what you need for your app.
}

Code defines the content of the reset code an expiration time boundary and user supplied data.

Jump to

Keyboard shortcuts

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