{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.3.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package totp\n\n## Functions\n\n```go\nfunc GenerateBackupCodes(count int) ([]string, error)\n```\nGenerateBackupCodes creates random backup codes\n\n## Types\n\n```go\ntype AuthProvider interface {\n\t// Generate2FASecret creates a new secret for a user\n\tGenerate2FASecret(userID int, issuer, accountName string) (*sectypes.TwoFactorSecret, error)\n\n\t// Validate2FACode verifies a TOTP code\n\tValidate2FACode(secret string, code string) (bool, error)\n\n\t// Enable2FA activates 2FA for a user (store secret in your database)\n\tEnable2FA(userID int, secret string, backupCodes []string) error\n\n\t// Disable2FA deactivates 2FA for a user\n\tDisable2FA(userID int) error\n\n\t// Get2FAStatus checks if user has 2FA enabled\n\tGet2FAStatus(userID int) (bool, error)\n\n\t// Get2FASecret retrieves the user's 2FA secret\n\tGet2FASecret(userID int) (string, error)\n\n\t// GenerateBackupCodes creates backup codes for 2FA\n\tGenerateBackupCodes(userID int, count int) ([]string, error)\n\n\t// ValidateBackupCode checks and consumes a backup code\n\tValidateBackupCode(userID int, code string) (bool, error)\n}\n```\nAuthProvider defines interface for 2FA operations\n\n```go\ntype Authenticator struct {\n\t// contains filtered or unexported fields\n}\n```\nAuthenticator wraps an Authenticator and adds 2FA support\n\n```go\nfunc NewAuthenticator(baseAuth BaseAuthenticator, provider AuthProvider, config *Config) *Authenticator\n```\nNewAuthenticator creates a new 2FA-enabled authenticator\n\n```go\nfunc (t *Authenticator) Authenticate(r *http.Request) (*sectypes.UserContext, error)\n```\nAuthenticate delegates to base authenticator\n\n```go\nfunc (t *Authenticator) Disable2FA(userID int) error\n```\nDisable2FA removes 2FA from a user account\n\n```go\nfunc (t *Authenticator) Enable2FA(userID int, secret, verificationCode string) error\n```\nEnable2FA completes 2FA setup after user confirms with a valid code\n\n```go\nfunc (t *Authenticator) Login(ctx context.Context, req sectypes.LoginRequest) (*sectypes.LoginResponse, error)\n```\nLogin authenticates with 2FA support\n\n```go\nfunc (t *Authenticator) Logout(ctx context.Context, req sectypes.LogoutRequest) error\n```\nLogout delegates to base authenticator\n\n```go\nfunc (t *Authenticator) RegenerateBackupCodes(userID int, count int) ([]string, error)\n```\nRegenerateBackupCodes creates new backup codes for a user\n\n```go\nfunc (t *Authenticator) Setup2FA(userID int, issuer, accountName string) (*sectypes.TwoFactorSecret, error)\n```\nSetup2FA initiates 2FA setup for a user\n\n```go\ntype BaseAuthenticator interface {\n\tLogin(ctx context.Context, req sectypes.LoginRequest) (*sectypes.LoginResponse, error)\n\tLogout(ctx context.Context, req sectypes.LogoutRequest) error\n\tAuthenticate(r *http.Request) (*sectypes.UserContext, error)\n}\n```\nBaseAuthenticator is the subset of security.Authenticator that Authenticator wraps. It is declared here so totp does not import the core security package.\n\n```go\ntype Config struct {\n\tAlgorithm  string // SHA1, SHA256, SHA512\n\tDigits     int    // Number of digits in code (6 or 8)\n\tPeriod     int    // Time step in seconds (default 30)\n\tSkewWindow int    // Number of time steps to check before/after (default 1)\n}\n```\nConfig holds TOTP configuration\n\n```go\nfunc DefaultConfig() *Config\n```\nDefaultConfig returns standard TOTP configuration\n\n```go\ntype Generator struct {\n\t// contains filtered or unexported fields\n}\n```\nGenerator handles TOTP code generation and validation\n\n```go\nfunc NewGenerator(config *Config) *Generator\n```\nNewGenerator creates a new TOTP generator with config\n\n```go\nfunc (t *Generator) GenerateCode(secret string, timestamp time.Time) (string, error)\n```\nGenerateCode creates a TOTP code for a given time\n\n```go\nfunc (t *Generator) GenerateQRCodeURL(secret, issuer, accountName string) string\n```\nGenerateQRCodeURL creates a URL for QR code generation\n\n```go\nfunc (t *Generator) GenerateSecret() (string, error)\n```\nGenerateSecret creates a random base32-encoded secret\n\n```go\nfunc (t *Generator) ValidateCode(secret, code string) (bool, error)\n```\nValidateCode checks if a code is valid for the secret\n\n```go\ntype MemoryProvider struct {\n\t// contains filtered or unexported fields\n}\n```\nMemoryProvider is an in-memory implementation of AuthProvider for testing/examples\n\n```go\nfunc NewMemoryProvider(config *Config) *MemoryProvider\n```\nNewMemoryProvider creates a new in-memory 2FA provider\n\n```go\nfunc (m *MemoryProvider) Disable2FA(userID int) error\n```\nDisable2FA deactivates 2FA for a user\n\n```go\nfunc (m *MemoryProvider) Enable2FA(userID int, secret string, backupCodes []string) error\n```\nEnable2FA activates 2FA for a user\n\n```go\nfunc (m *MemoryProvider) Generate2FASecret(userID int, issuer, accountName string) (*sectypes.TwoFactorSecret, error)\n```\nGenerate2FASecret creates a new secret for a user\n\n```go\nfunc (m *MemoryProvider) GenerateBackupCodes(userID int, count int) ([]string, error)\n```\nGenerateBackupCodes creates backup codes for 2FA\n\n```go\nfunc (m *MemoryProvider) Get2FASecret(userID int) (string, error)\n```\nGet2FASecret retrieves the user's 2FA secret\n\n```go\nfunc (m *MemoryProvider) Get2FAStatus(userID int) (bool, error)\n```\nGet2FAStatus checks if user has 2FA enabled\n\n```go\nfunc (m *MemoryProvider) Validate2FACode(secret string, code string) (bool, error)\n```\nValidate2FACode verifies a TOTP code\n\n```go\nfunc (m *MemoryProvider) ValidateBackupCode(userID int, code string) (bool, error)\n```\nValidateBackupCode checks and consumes a backup code\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/security/totp","name":"totp","synopsis":"","isRedistributable":true}
