auth

package
v0.0.0-...-3171a72 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package auth handles password hashing, session generation, and bearer token generation.

Index

Constants

View Source
const TokenPrefix = "trov_"

TokenPrefix is prepended to all generated tokens for identification by secret scanners.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(hash, password string) bool

CheckPassword verifies a plaintext password against a bcrypt hash.

func CheckPasswordStrength

func CheckPasswordStrength(password, policy string) (ok bool, feedback string)

CheckPasswordStrength validates a password against the given policy level. Returns ok=true if the password passes, or ok=false with a human-readable feedback message. Policy levels: "off" (always passes), "basic" (min 8 chars), "strict" (zxcvbn score >= 3).

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a plaintext password with bcrypt.

func HashToken

func HashToken(token string) string

HashToken returns the SHA256 hex hash of a bearer token. Accepts tokens with or without the trov_ prefix.

func NewSessionID

func NewSessionID() (string, error)

NewSessionID generates a cryptographically random session ID.

func NewToken

func NewToken() (plaintext, hash string, err error)

NewToken generates a random bearer token and returns both the plaintext token (to be returned to the user once) and the SHA256 hash (stored in the database).

func PasswordStrengthScore

func PasswordStrengthScore(password string) int

PasswordStrengthScore returns a 0-4 score for UI strength meters.

func StripTokenPrefix

func StripTokenPrefix(token string) string

StripTokenPrefix removes the trov_ prefix if present (for backward compat with old tokens).

Types

This section is empty.

Jump to

Keyboard shortcuts

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