Files
decypharr/pkg/web/auth.go
Mukhtar Akere 07f1d0f28d - Fix symlinks % bug
- A cleaner settings page
- More bug fixes
2025-04-25 12:36:12 +01:00

35 lines
848 B
Go

package web
import (
"github.com/sirrobot01/decypharr/internal/config"
"golang.org/x/crypto/bcrypt"
"net/http"
)
func (ui *Handler) verifyAuth(username, password string) bool {
// If you're storing hashed password, use bcrypt to compare
if username == "" {
return false
}
auth := config.Get().GetAuth()
if auth == nil {
return false
}
if username != auth.Username {
return false
}
err := bcrypt.CompareHashAndPassword([]byte(auth.Password), []byte(password))
return err == nil
}
func (ui *Handler) skipAuthHandler(w http.ResponseWriter, r *http.Request) {
cfg := config.Get()
cfg.UseAuth = false
if err := cfg.Save(); err != nil {
ui.logger.Error().Err(err).Msg("failed to save config")
http.Error(w, "failed to save config", http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/", http.StatusSeeOther)
}