htpasswd

package
v0.0.0-...-4395a40 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package htpasswd contains utilities for manipulating .htpasswd files

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExists indicates the specified user already exists
	ErrExists = errors.New("user already exists")
	// ErrNotExists indicates the specified user does not exist
	ErrNotExists = errors.New("user does not exist")
	// ErrInvalidAlgorithm indicates the htpasswd entry doesn't contain a
	// valid algorithm signature
	ErrInvalidAlgorithm = errors.New("invalid algorithm")
	// ErrInvalidPassword indicates the offered password doesn't match
	ErrInvalidPassword = errors.New("invalid password")
)

Functions

func CreateUser

func CreateUser(file, user, passwd string, algo Hasher) error

CreateUser creates a record in the named file with the named password and hash algorithm

func DeleteUser

func DeleteUser(file, user string) error

DeleteUser deletes the named user from the named file

func UpdateUser

func UpdateUser(file, user, passwd string, algo Hasher) error

UpdateUser will update the password for the named user in the named file

func VerifyUser

func VerifyUser(file, user, passwd string) error

VerifyUser will check if the given user and password are matching with the content of the given file

Types

type Apr1

type Apr1 struct{}

Apr1 facilitates apr1 style hashing

func (*Apr1) Hash

func (*Apr1) Hash(passwd string) (string, error)

Hash returns the hashed variant of the password or an error

func (*Apr1) Match

func (*Apr1) Match(password, hashedPassword string) error

Match verifier the hashed password using the original

func (*Apr1) Name

func (*Apr1) Name() string

Name returns the name of the hasher

func (*Apr1) Prefix

func (*Apr1) Prefix() string

Prefix returns the hasher's prefix

type Bcrypt

type Bcrypt struct{}

Bcrypt facilitates bcrypt style hashing

func (*Bcrypt) Hash

func (*Bcrypt) Hash(password string) (string, error)

Hash returns the hashed variant of the password or an error

func (*Bcrypt) Match

func (*Bcrypt) Match(password, hashedPassword string) error

Match verifier the hashed password using the original

func (*Bcrypt) Name

func (*Bcrypt) Name() string

Name returns the name of the hasher

func (*Bcrypt) Prefix

func (*Bcrypt) Prefix() string

Prefix returns the hasher's prefix

type Hasher

type Hasher interface {
	Hash(password string) (string, error)
	Match(password, hashedPassword string) error
	Name() string
	Prefix() string
}

Hasher interface implemented by hash algos

type Passwds

type Passwds map[string]string

Passwds name => hash

func Parse

func Parse(htpasswdBytes []byte) (Passwds, error)

Parse parses a slice of bytes in htpasswd style

func ParseFile

func ParseFile(file string) (Passwds, error)

ParseFile parses a .htpasswd file and returns a Passwd type

func (Passwds) Bytes

func (pp Passwds) Bytes() []byte

Bytes will return the Passwd as a byte slice

func (Passwds) CreateUser

func (pp Passwds) CreateUser(user, passwd string, algo Hasher) error

CreateUser will create a new user in the given Passwd object using the given name, password and hashing algorithm

func (Passwds) DeleteUser

func (pp Passwds) DeleteUser(user string) error

DeleteUser deletes the named user from the named file

func (Passwds) UpdateUser

func (pp Passwds) UpdateUser(user, passwd string, algo Hasher) error

UpdateUser will update the password for the named user using the given name, password and hashing algorithm

func (Passwds) VerifyUser

func (pp Passwds) VerifyUser(user, passwd string) error

VerifyUser will check if the given user and password are matching with the given Passwd object

func (Passwds) WriteFile

func (pp Passwds) WriteFile(file string) error

WriteFile will write the Passwds object to the given file

type Sha

type Sha struct{}

Sha facilitates sha1 style hashing

func (*Sha) Hash

func (ss *Sha) Hash(passwd string) (string, error)

Hash returns the hashed variant of the password or an error

func (*Sha) Match

func (*Sha) Match(password, hashedPassword string) error

Match verifier the hashed password using the original

func (*Sha) Name

func (*Sha) Name() string

Name returns the name of the hasher

func (*Sha) Prefix

func (*Sha) Prefix() string

Prefix returns the hasher's prefix

type Sha256

type Sha256 struct{}

Sha256 facilitates sha256 style hashing

func (*Sha256) Hash

func (ss *Sha256) Hash(passwd string) (string, error)

Hash returns the hashed variant of the password or an error

func (*Sha256) Match

func (*Sha256) Match(password, hashedPassword string) error

Match verifier the hashed password using the original

func (*Sha256) Name

func (*Sha256) Name() string

Name returns the name of the hasher

func (*Sha256) Prefix

func (*Sha256) Prefix() string

Prefix returns the hasher's prefix

type Sha512

type Sha512 struct{}

Sha512 facilitates sha512 style hashing

func (*Sha512) Hash

func (ss *Sha512) Hash(passwd string) (string, error)

Hash returns the hashed variant of the password or an error

func (*Sha512) Match

func (*Sha512) Match(password, hashedPassword string) error

Match verifier the hashed password using the original

func (*Sha512) Name

func (*Sha512) Name() string

Name returns the name of the hasher

func (*Sha512) Prefix

func (*Sha512) Prefix() string

Prefix returns the hasher's prefix

type Ssha

type Ssha struct{}

Ssha facilitates ssha style hashing

func (*Ssha) Hash

func (ss *Ssha) Hash(passwd string) (string, error)

Hash returns the hashed variant of the password or an error

func (*Ssha) Match

func (*Ssha) Match(password, hashedPassword string) error

Match verifier the hashed password using the original

func (*Ssha) Name

func (*Ssha) Name() string

Name returns the name of the hasher

func (*Ssha) Prefix

func (*Ssha) Prefix() string

Prefix returns the hasher's prefix

type UserError

type UserError struct {
	Name string
	Hint string
	Err  error
}

UserError indicates an error associated to the specified user

func (*UserError) Error

func (e *UserError) Error() string

func (*UserError) Unwrap

func (e *UserError) Unwrap() error

Jump to

Keyboard shortcuts

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