Files
wol-sol-agent/auth/auth.go
2025-11-11 17:19:49 +01:00

36 lines
835 B
Go

package auth
import (
"crypto/sha256"
"encoding/hex"
"fmt"
)
// Authenticator handles authentication
type Authenticator struct {
user string
password string
hash string
}
// New creates a new authenticator with the given credentials
func New(username, password string) *Authenticator {
authString := fmt.Sprintf("%s:%s", username, password)
hash := sha256.Sum256([]byte(authString))
hashStr := hex.EncodeToString(hash[:])
return &Authenticator{
user: username,
password: password,
hash: hashStr,
}
}
// Verify checks if the provided username and password are valid
func (a *Authenticator) Verify(username, password string) bool {
authString := fmt.Sprintf("%s:%s", username, password)
hash := sha256.Sum256([]byte(authString))
hashStr := hex.EncodeToString(hash[:])
return hashStr == a.hash
}