htpasswd

package module
v0.0.0-...-e61fa4b Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2017 License: MIT Imports: 8 Imported by: 0

README

Travis CI

This is a simple utility library to manipulate htpasswd files

If you want to authenticate against a htpasswd file use something like https://github.com/abbot/go-http-auth .

Supported hashing algorithms:

  • sha (do not use except for legacy support situations)
  • bcrypt

This is what you can

Set user credentials in a htpasswd file:

file := "/tmp/demo.htpasswd"
name := "joe"
password := "secret"
err := htpasswd.SetPassword(file, name, password, htpasswd.HashBCrypt)

Remove a user:

err := htpasswd.RemoveUser(file, name)

Read user hash table:

passwords, err := htpasswd.ParseHtpasswdFile(file)

Have fun.

Documentation

Overview

Package htpasswd is utility package to manipulate htpasswd files. I supports\ bcrypt and sha hashes.

Index

Constants

View Source
const (
	// HashBCrypt bcrypt - recommended
	HashBCrypt = "bcrypt"
	// HashSHA sha5 insecure - do not use
	HashSHA = "sha"
)
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 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 SetHtpasswdHash

func SetHtpasswdHash(file, name, hash string) error

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

func SetPasswordHash(file, user, hash string) error

SetPasswordHash directly set a hash for a user in a file

Types

type HashAlgorithm

type HashAlgorithm string

HashAlgorithm enum for hashing algorithms

type HashedPasswords

type HashedPasswords map[string]string

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

Jump to

Keyboard shortcuts

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