feat(sol): UDP + HTTP listener
This commit is contained in:
35
auth/auth.go
Normal file
35
auth/auth.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user