mirror of
https://github.com/parkan/go-hauk.git
synced 2026-05-08 16:47:46 +02:00
add auth layer
This commit is contained in:
18
auth/password.go
Normal file
18
auth/password.go
Normal file
@@ -0,0 +1,18 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user