htpasswd

package
v1.5.26 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PasswordSeparator separates passwords from hashes
	PasswordSeparator = ":"
	// LineSeparator separates password records
	LineSeparator = "\n"
)
View Source
const MaxHtpasswdFilesize = 8 * 1024 * 1024

MaxHtpasswdFilesize if your htpassd file is larger than 8MB, then your are doing it wrong

Variables

This section is empty.

Functions

func HashApr1

func HashApr1(password string) (string, error)

func HashBCrypt

func HashBCrypt(password string) (string, error)

func HashSha

func HashSha(password string) string

func RemoveUser

func RemoveUser(file, user string) error

RemoveUser remove an existing user from a file, returns an error, if the user does not \ exist in the file

func SetPassword

func SetPassword(file, name, password string, algo Algorithm) error

SetPassword set password for a user with a given hashing algorithm

func SetPasswordHash

func SetPasswordHash(file, user, hash string) error

SetPasswordHash directly set a hash for a user in a file

Types

type Accounts

type Accounts map[string]string

Accounts name => hash

func ParseHtpasswdFile

func ParseHtpasswdFile(file string) (users Accounts, err error)

ParseHtpasswdFile parse htpasswd file

func (Accounts) Bytes

func (a Accounts) Bytes() (passwordBytes []byte)

Bytes bytes representation

func (Accounts) SetPassword

func (a Accounts) SetPassword(name, password string, algo Algorithm) (err error)

SetPassword set a password for a user with a hashing algo

func (Accounts) WriteToFile

func (a Accounts) WriteToFile(file string) error

WriteToFile put them to a file will be overwritten or created

type Algorithm

type Algorithm string
const (
	// AlgoAPR1 Apache MD5 crypt - legacy
	AlgoAPR1 Algorithm = "apr1"
	// AlgoBCrypt bcrypt - recommended
	AlgoBCrypt Algorithm = "bcrypt"
	// AlgoSHA sha5 insecure - do not use
	AlgoSHA Algorithm = "sha"
)

Jump to

Keyboard shortcuts

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