package htpasswd

import "github.com/GehirnInc/crypt/apr1_crypt"

// Apr1 facilitates apr1 style hashing
type Apr1 struct{}

// Hash returns the hashed variant of the password or an error
func (*Apr1) Hash(passwd string) (string, error) {
	return apr1_crypt.New().Generate([]byte(passwd), nil)
}

// Match verifier the hashed password using the original
func (*Apr1) Match(password, hashedPassword string) error {
	return apr1_crypt.New().Verify(hashedPassword, []byte(password))
}

// Name returns the name of the hasher
func (*Apr1) Name() string { return "apr1" }

// Prefix returns the hasher's prefix
func (*Apr1) Prefix() string { return "$apr1$" }