backend/dbhandler/user_pass_auth.go
2025-03-18 23:27:27 +02:00

43 lines
1.3 KiB
Go

package dbhandler
import (
"context"
"git.acooldomain.co/server-manager/backend/models"
"golang.org/x/crypto/bcrypt"
)
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(bytes), err
}
type InviteToken struct {
Email string
Permissions models.Permission
Token string
}
type UserSignupRequest struct {
Token InviteToken
Username string
Password string
}
type UserPassAuthanticationDbHandler interface {
// Read Only
AuthenticateUser(ctx context.Context, username string, password string) (*models.User, error)
ListUsers(ctx context.Context) ([]models.User, error)
// Write
CreateUser(ctx context.Context, username string, password string, permissions models.Permission, email string, maxOwnedServers uint) error
RemoveUser(ctx context.Context, username string) error
SetPermissions(ctx context.Context, username string, permissions models.Permission) error
SetPassword(ctx context.Context, username string, password string) error
}
type InviteTokenDbHandler interface {
SaveInviteToken(ctx context.Context, email string, permissions models.Permission) (string, error)
GetInviteToken(ctx context.Context, token string) (*InviteToken, error)
}