local

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package local provides password hashing and verification for application-owned user stores.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a password with bcrypt, using its default work factor. Applications must enforce their own password and account policies before calling it.

func VerifyPassword

func VerifyPassword(hash, password string) error

VerifyPassword compares a supplied password with a stored bcrypt hash.

Types

type CredentialStore

type CredentialStore[User any] interface {
	// LookupCredential fetches a user's current bcrypt password hash.
	LookupCredential(context.Context, string) (User, string, error)
}

CredentialStore loads an application-owned user and a bcrypt password hash. Unknown or disabled accounts must return auth.ErrInvalidCredentials.

type Service

type Service[User any] struct {
	// Credentials provides application-owned user lookup and account policy.
	Credentials CredentialStore[User]
	// Sessions provides durable, revocable session persistence.
	Sessions session.Manager[User]
}

Service verifies local passwords and issues hashed server-side sessions.

func (Service[User]) SignIn

func (s Service[User]) SignIn(ctx context.Context, username, password string) (User, string, error)

SignIn verifies credentials and creates a new opaque session. The caller writes the session cookie using session.CookieConfig.

Jump to

Keyboard shortcuts

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