mirror of
https://github.com/coalaura/whiskr.git
synced 2025-09-08 17:06:42 +00:00
authentication
This commit is contained in:
18
env.go
18
env.go
@@ -9,7 +9,6 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/goccy/go-yaml"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
type EnvTokens struct {
|
||||
@@ -29,8 +28,10 @@ type EnvUser struct {
|
||||
}
|
||||
|
||||
type EnvAuthentication struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Users []EnvUser `json:"users"`
|
||||
lookup map[string]*EnvUser
|
||||
|
||||
Enabled bool `json:"enabled"`
|
||||
Users []*EnvUser `json:"users"`
|
||||
}
|
||||
|
||||
type Environment struct {
|
||||
@@ -94,17 +95,14 @@ func (e *Environment) Init() error {
|
||||
log.Warning("Missing token.exa, web search unavailable")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
// create user lookup map
|
||||
e.Authentication.lookup = make(map[string]*EnvUser)
|
||||
|
||||
func (e *Environment) Authenticate(username, password string) bool {
|
||||
for _, user := range e.Authentication.Users {
|
||||
if user.Username == username {
|
||||
return bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)) == nil
|
||||
}
|
||||
e.Authentication.lookup[user.Username] = user
|
||||
}
|
||||
|
||||
return false
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Environment) Store() error {
|
||||
|
Reference in New Issue
Block a user