02235c36bc
Signed-off-by: Alejandro Mery <amery@jpi.io>
50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package htpasswd
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
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")
|
|
)
|
|
|
|
// UserError indicates an error associated to the specified user
|
|
type UserError struct {
|
|
Name string
|
|
Hint string
|
|
Err error
|
|
}
|
|
|
|
func (e *UserError) Error() string {
|
|
var buf strings.Builder
|
|
var reason string
|
|
|
|
if e.Hint != "" {
|
|
reason = e.Hint
|
|
} else {
|
|
reason = e.Err.Error()
|
|
}
|
|
|
|
if e.Name == "" {
|
|
return reason
|
|
}
|
|
|
|
_, _ = buf.WriteString(e.Name)
|
|
_, _ = buf.WriteString(": ")
|
|
_, _ = buf.WriteString(reason)
|
|
return buf.String()
|
|
}
|
|
|
|
func (e *UserError) Unwrap() error {
|
|
return e.Err
|
|
}
|