pin

package
v0.1.70 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pin is the PIN of the section for adults (R04, R35): its form, its hash and the count of wrong PINs that closes its input. The PIN is a barrier of the interface, not of the server; the count is what keeps it from being tried by the server, one for every device of the account.

Index

Constants

View Source
const (
	MaxFailures = 5
	Window      = 15 * time.Minute
	LockFor     = 15 * time.Minute
)

The count (R04, R35): no more than MaxFailures wrong PINs in any Window. The count is of the wrong PINs of the last Window, and the one that brings it to MaxFailures closes the input for LockFor from itself.

Variables

This section is empty.

Functions

func Hash

func Hash(pin string) string

Hash is the PIN's argon2id, to Put.

func Valid

func Valid(pin string) bool

Valid says whether pin has the contract's form: from 4 to 6 digits.

Types

type Check

type Check struct {
	// Matches says it is the PIN set.
	Matches bool
	// Left is how many wrong PINs are left before the input closes, beside a
	// wrong one; 0 when this one closed it.
	Left int
	// LockedUntil is when the input opens, beside the wrong PIN that closed it.
	LockedUntil time.Time
}

Check is how a PIN compared with the one set.

type State

type State struct {
	// Hash is the PIN's argon2id, or empty while none is set.
	Hash string
	// Failed is when each wrong PIN of the last Window was given, the oldest
	// first; it may hold older ones, which no longer count.
	Failed []time.Time
	// LockedUntil is when the input opens once it closed; zero while it is open.
	LockedUntil time.Time
}

State is what the account keeps of its PIN.

func (*State) Locked

func (s *State) Locked(now time.Time) bool

Locked says whether the input is closed at now.

func (*State) Put

func (s *State) Put(hash string)

Put sets the PIN by its Hash, and opens the input with its count cleared.

func (*State) Set

func (s *State) Set() bool

Set says whether a PIN is set.

func (*State) Try

func (s *State) Try(pin string, now time.Time) Check

Try compares pin with the one set at now, while the input is open. The right PIN clears the count. A wrong one is counted with those of the last Window, and the one that brings them to MaxFailures closes the input.

Jump to

Keyboard shortcuts

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