mirror of
https://github.com/parkan/go-hauk.git
synced 2026-05-08 16:47:46 +02:00
19 lines
366 B
Go
19 lines
366 B
Go
package auth
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
type PasswordAuth struct {
|
|
hash []byte
|
|
}
|
|
|
|
func NewPasswordAuth(hash string) *PasswordAuth {
|
|
return &PasswordAuth{hash: []byte(hash)}
|
|
}
|
|
|
|
func (p *PasswordAuth) Authenticate(_, pass string) error {
|
|
if err := bcrypt.CompareHashAndPassword(p.hash, []byte(pass)); err != nil {
|
|
return ErrAuthFailed
|
|
}
|
|
return nil
|
|
}
|