1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-09-08 17:06:42 +00:00

authentication

This commit is contained in:
Laura
2025-08-16 17:18:48 +02:00
parent a138378f19
commit e10c3dce3f
7 changed files with 357 additions and 18 deletions

18
env.go
View File

@@ -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 {