Help us shape the future of Go! Take the 2026 Go Developer Survey

tPassword

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 4 Imported by: 0

README

tPassword

A small Go library for generating random passwords, built on crypto/rand.

Compatibility

  • Go 1.26+

Installation

go get github.com/tPortal-Dev/tPassword

Usage

Generate
import "github.com/tPortal-Dev/tPassword"

// default configuration
password, err := tPassword.Generate(16)

// custom options
password2, err := tPassword.Generate(16,
    tPassword.WithUppercase(),
    tPassword.WithSymbols(),
    tPassword.WithoutAmbiguous(),
)

// multiple passwords
passwords, err := tPassword.GenerateMulti(3, 16)
Generate with custom charset
import "github.com/tPortal-Dev/tPassword"

password, err := tPassword.GenerateWithCustomCharset(16, "abcd1234?!-_")

// multiple passwords
passwords, err := tPassword.GenerateMultiWithCustomCharset(3, 16, "abcd1234?!-_")
Default behavior

By default, generated passwords contain:

  • lowercase letters (a-z)
  • digits (0-9)
Options

The default options can be customized by passing Options to Generate / GenerateMulti:

Option Effect
WithUppercase() Adds uppercase letters
WithSymbols() Adds symbols (.?!&#()$%+=_-@)
WithoutLowercase() Removes lowercase letters
WithoutDigits() Removes digits
WithoutAmbiguous() Removes ambiguous characters (O, 0, 1, l, I)

[!WARNING] At least one character set must remain enabled. Otherwise, Generate and GenerateMulti return ErrEmptyCharset.

Errors

The library exposes two sentinel errors that can be checked with errors.Is:

var (
    tPassword.ErrEmptyCharset  // no character set selected
    tPassword.ErrInvalidLength // length <= 0
)

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyCharset  = errors.New("no charset selected")
	ErrInvalidLength = errors.New("invalid length")
)

Functions

func Generate

func Generate(length int, options ...Option) (string, error)

func GenerateMulti

func GenerateMulti(count, length int, options ...Option) ([]string, error)

func GenerateMultiWithCustomCharset

func GenerateMultiWithCustomCharset(count, length int, charset string) ([]string, error)

func GenerateWithCustomCharset

func GenerateWithCustomCharset(length int, charset string) (string, error)

Types

type Option

type Option func(*config)

func WithSymbols

func WithSymbols() Option

func WithUppercase

func WithUppercase() Option

func WithoutAmbiguous added in v1.1.5

func WithoutAmbiguous() Option

func WithoutDigits added in v1.1.4

func WithoutDigits() Option

func WithoutLowercase added in v1.1.4

func WithoutLowercase() Option

Jump to

Keyboard shortcuts

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