Documentation ¶
Overview ¶
Package htpasswd is utility package to manipulate htpasswd files. I supports\ bcrypt and sha hashes.
Index ¶
Constants ¶
const ( // HashBCrypt bcrypt - recommended HashBCrypt = "bcrypt" // HashSHA sha5 insecure - do not use HashSHA = "sha" )
const ( // PasswordSeparator separates passwords from hashes PasswordSeparator = ":" // LineSeparator separates password records LineSeparator = "\n" )
const MaxHtpasswdFilesize = 8 * 1024 * 1024
MaxHtpasswdFilesize if your htpassd file is larger than 8MB, then your are doing it wrong
Variables ¶
var ErrNotExist = errors.New("user did not exist in file")
ErrNotExist is the error returned when a user does not exist.
Functions ¶
func RemoveUser ¶
RemoveUser remove an existing user from a file, returns an error, if the user does not \ exist in the file
func SetHtpasswdHash ¶
SetHtpasswdHash set password hash for a user
func SetPassword ¶
func SetPassword(file, name, password string, hashAlgorithm HashAlgorithm) error
SetPassword set password for a user with a given hashing algorithm
func SetPasswordHash ¶
SetPasswordHash directly set a hash for a user in a file
Types ¶
type HashedPasswords ¶
HashedPasswords name => hash
func ParseHtpasswd ¶
func ParseHtpasswd(htpasswdBytes []byte) (passwords HashedPasswords, err error)
ParseHtpasswd parse htpasswd bytes
func ParseHtpasswdFile ¶
func ParseHtpasswdFile(file string) (passwords HashedPasswords, err error)
ParseHtpasswdFile load a htpasswd file
func (HashedPasswords) Bytes ¶
func (hp HashedPasswords) Bytes() (passwordBytes []byte)
Bytes bytes representation
func (HashedPasswords) SetPassword ¶
func (hp HashedPasswords) SetPassword(name, password string, hashAlgorithm HashAlgorithm) (err error)
SetPassword set a password for a user with a hashing algo
func (HashedPasswords) WriteToFile ¶
func (hp HashedPasswords) WriteToFile(file string) error
WriteToFile put them to a file will be overwritten or created