htpasswd

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashApacheMD5

func HashApacheMD5(password string) (string, error)

HashApacheMD5 implements Apache's MD5 algorithm

func HashBcrypt

func HashBcrypt(password string) (string, error)

HashBcrypt hashes password using bcrypt

func HashCrypt

func HashCrypt(password string) (string, error)

HashCrypt implements Unix crypt() using DES-based algorithm

func HashPassword

func HashPassword(password string, hashType HashType) (string, error)

HashPassword hashes a password using the specified algorithm

func HashSHA1

func HashSHA1(password string) (string, error)

HashSHA1 hashes password using SHA1 (Apache format)

func HashSHA256

func HashSHA256(password string) (string, error)

HashSHA256 hashes password using SHA256

func HashSHA512

func HashSHA512(password string) (string, error)

HashSHA512 hashes password using SHA512

func ValidatePassword

func ValidatePassword(password string) error

ValidatePassword validates a password

func ValidateUsername

func ValidateUsername(username string) error

ValidateUsername validates a username according to htpasswd rules

func VerifyApacheMD5

func VerifyApacheMD5(password, hash string) bool

VerifyApacheMD5 verifies Apache MD5 hash

func VerifyBcrypt

func VerifyBcrypt(password, hash string) bool

VerifyBcrypt verifies bcrypt hash

func VerifyCrypt

func VerifyCrypt(password, hash string) bool

VerifyCrypt verifies crypt hash

func VerifyPassword

func VerifyPassword(password, hash string) bool

VerifyPassword verifies a password against a hash

func VerifySHA1

func VerifySHA1(password, hash string) bool

VerifySHA1 verifies SHA1 hash

func VerifySHA256

func VerifySHA256(password, hash string) bool

VerifySHA256 verifies SHA256 hash

func VerifySHA512

func VerifySHA512(password, hash string) bool

VerifySHA512 verifies SHA512 hash

Types

type Container

type Container struct {
	// contains filtered or unexported fields
}

func NewContainer

func NewContainer() *Container

NewContainer creates a new htpasswd container

func NewFromFile

func NewFromFile(path string) (*Container, error)

NewFromFile creates a container from file

func NewFromReader

func NewFromReader(src io.Reader) (*Container, error)

NewFromReader creates a container from reader

func (*Container) AddUser

func (c *Container) AddUser(username, hash string) error

AddUser adds or updates a user entry

func (*Container) AddUserPassword

func (c *Container) AddUserPassword(username string, password string) error

AddUserPassword adds a user and password with bcrypt

func (*Container) AddUserWithHash

func (c *Container) AddUserWithHash(username string, password string, hashType HashType) error

AddUserWithHash adds a user and password

func (*Container) Count

func (c *Container) Count() int

Count returns the number of users

func (*Container) DeleteUser

func (c *Container) DeleteUser(username string) error

DeleteUser removes a user entry

func (*Container) GetUser

func (c *Container) GetUser(username string) (*Entry, error)

GetUser retrieves a user entry

func (*Container) ListUsers

func (c *Container) ListUsers() []string

ListUsers returns all usernames

func (*Container) Read

func (c *Container) Read(src io.Reader) error

Load reads and parses a htpasswd source

func (*Container) UserExists

func (c *Container) UserExists(username string) bool

UserExists checks if a user exists

func (*Container) VerifyUser

func (c *Container) VerifyUser(username string, password string) (bool, error)

VerifyUser validate a user password

func (*Container) Write

func (c *Container) Write(dest io.Writer) error

Save writes the htpasswd file

type Entry

type Entry struct {
	Username string
	Hash     string
}

Entry represents a single htpasswd entry

type HashType

type HashType int

HashType represents the different hash algorithms supported

const (
	HashTypeBcrypt HashType = iota // Recommended algorithm
	HashTypeApacheMD5
	HashTypeSHA1
	HashTypeSHA256
	HashTypeSHA512
	HashTypeCrypt
	HashTypePlain
)

func DetectHashType

func DetectHashType(hash string) HashType

DetectHashType detects the hash type from a hash string

Jump to

Keyboard shortcuts

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