password

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CookieDecryptJwt

func CookieDecryptJwt(r *http.Request) (string, string, error)

func CookieDelete

func CookieDelete(w http.ResponseWriter, name string)

func CookieRefreshOrDelete

func CookieRefreshOrDelete(w http.ResponseWriter, r *http.Request) (string, string, bool)

func CookieSetTokens

func CookieSetTokens(w http.ResponseWriter, a string, r string)

func HttpRedirect

func HttpRedirect(w http.ResponseWriter, r *http.Request, redirectFunc func(r *http.Request) string, defaultRoute string) bool

func InitJwt

func InitJwt(params AuthParams)

func MiddlewareVerifyJwtAndInjectUserId

func MiddlewareVerifyJwtAndInjectUserId(next http.Handler) http.Handler

func NewTokenPair

func NewTokenPair(j JwtParams) (string, string, string, error)

func ParseOrRefreshToken

func ParseOrRefreshToken(a string, r string) (string, string, error)

Types

type AuthParams

type AuthParams struct {
	Secret         string
	PublicKeyPath  string
	PrivateKeyPath string
}

type BitError

type BitError uint64
const (
	// User-facing errors (0-31)
	ErrUsernameTooShort      BitError = 1 << 0
	ErrUsernameTooLong       BitError = 1 << 1
	ErrUsernameInvalidFormat BitError = 1 << 2
	ErrUsernameTaken         BitError = 1 << 3
	ErrPasswordTooShort      BitError = 1 << 4
	ErrPasswordTooLong       BitError = 1 << 5
	ErrPassNoMatch           BitError = 1 << 6
	ErrBadLogin              BitError = 1 << 7
	ErrInternalServer        BitError = 1 << 8
	ErrTOTPMismatch          BitError = 1 << 14

	// System errors (32-63)
	ErrHashPassword        BitError = 1 << 32
	ErrDbInsertUser        BitError = 1 << 33
	ErrParsingJwt          BitError = 1 << 35
	ErrJwtMethodBad        BitError = 1 << 39
	ErrJwtInvalid          BitError = 1 << 38
	ErrJwtInvalidInDb      BitError = 1 << 40
	ErrDbInsertToken       BitError = 1 << 42
	ErrJwtGoodAccBadRef    BitError = 1 << 44
	ErrDbSelectUserSubject BitError = 1 << 48
	ErrUuidFailed          BitError = 1 << 49
)

func (BitError) Add

func (e BitError) Add(err BitError) BitError

func (BitError) Count

func (e BitError) Count() int

func (BitError) Error

func (e BitError) Error() string

func (BitError) GetErrors

func (e BitError) GetErrors() []error

func (BitError) GetSystemErrors

func (e BitError) GetSystemErrors() BitError

func (BitError) GetUserErrors

func (e BitError) GetUserErrors() BitError

func (BitError) Has

func (e BitError) Has(err BitError) bool

func (BitError) IsPasswordError

func (e BitError) IsPasswordError() bool

func (BitError) IsRepeatedError

func (e BitError) IsRepeatedError() bool

func (BitError) IsUsernameError

func (e BitError) IsUsernameError() bool

func (BitError) RenderFullMessages

func (e BitError) RenderFullMessages() []string

type ConfigJwt

type ConfigJwt struct {
	Secret        string
	SecureCookie  bool
	AccessExpiry  time.Duration
	RefreshExpiry time.Duration
	PublicKey     *rsa.PublicKey
	PrivateKey    *rsa.PrivateKey
}

func LocalConfig

func LocalConfig() *ConfigJwt

type CustomClaims

type CustomClaims struct {
	jwt.RegisteredClaims
	JwtType  string `json:"jwt_type"`
	Family   string `json:"family"`
	UserName string `json:"user"`
}

func ParseToken

func ParseToken(t string) (CustomClaims, error)

type FormState

type FormState struct {
	Username string
	Errors   BitError
}

type JwtParams

type JwtParams struct {
	Subject  string `json:"sub"`
	Family   string `json:"family"`
	UserName string `json:"user"`
}

type PasswordHandler

type PasswordHandler struct {
	UsernameValidate func(s string) BitError
	Database         storage.DbPassword
	Ui               PasswordUi
	Redirects        PasswordRedirects
}

func (PasswordHandler) ChangePassHandler

func (p PasswordHandler) ChangePassHandler(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) ChangePass_GET

func (p PasswordHandler) ChangePass_GET(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) ChangePass_POST

func (p PasswordHandler) ChangePass_POST(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) ChangePass_Work

func (p PasswordHandler) ChangePass_Work(username, password, repeated string) BitError

func (PasswordHandler) ForgotHandler

func (p PasswordHandler) ForgotHandler(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) Forgot_GET

func (p PasswordHandler) Forgot_GET(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) Forgot_POST

func (p PasswordHandler) Forgot_POST(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) SignInHandler

func (p PasswordHandler) SignInHandler(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) SignIn_GET

func (p PasswordHandler) SignIn_GET(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) SignIn_POST

func (p PasswordHandler) SignIn_POST(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) SignIn_Work

func (p PasswordHandler) SignIn_Work(username, password string) (string, string, BitError)

func (PasswordHandler) SignOutEverywhereHandler

func (p PasswordHandler) SignOutEverywhereHandler(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) SignOutHandler

func (p PasswordHandler) SignOutHandler(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) SignUpHandler

func (p PasswordHandler) SignUpHandler(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) SignUp_GET

func (p PasswordHandler) SignUp_GET(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) SignUp_POST

func (p PasswordHandler) SignUp_POST(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) SignUp_Work

func (p PasswordHandler) SignUp_Work(username, password, repeated string) (string, string, BitError)

func (PasswordHandler) TotpHandler

func (p PasswordHandler) TotpHandler(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) Totp_GET

func (p PasswordHandler) Totp_GET(w http.ResponseWriter, r *http.Request)

func (PasswordHandler) Totp_POST

func (p PasswordHandler) Totp_POST(w http.ResponseWriter, r *http.Request)

type PasswordRedirects

type PasswordRedirects struct {
	BeforeSignUp  RedirectFunc
	BeforeSignIn  RedirectFunc
	BeforeSignOut RedirectFunc
	AfterSignUp   RedirectFunc
	AfterSignIn   RedirectFunc
	AfterSignOut  RedirectFunc
}

type PasswordUi

type PasswordUi struct {
	HtmlPageSignUp func(*http.Request, FormState) []byte
	HtmlPageSignIn func(*http.Request, FormState) []byte
	HtmlPageChange func(*http.Request, FormState) []byte
	HtmlPageForgot func(*http.Request, FormState) []byte
	HtmlPageTotp   func(r *http.Request, state FormState, qr []byte, skipRedirectUrl string, totpSecret string) []byte
}

type RedirectFunc

type RedirectFunc func(*http.Request) string

Directories

Path Synopsis
templ: version: v0.3.898
templ: version: v0.3.898

Jump to

Keyboard shortcuts

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