add auth layer

This commit is contained in:
Arkadiy Kukarkin
2025-12-23 12:23:32 +01:00
parent c4889d7d16
commit 725a673fb0
4 changed files with 148 additions and 0 deletions

18
auth/password.go Normal file
View 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
}