Files
modanubandHanzo Dev 912dd1c76f Initial release: CoreDNS web management application
Full-featured web UI for managing CoreDNS Corefile and host files with
diff preview, Docker-based reload, and master password authentication.
Built for MWIT-LINK infrastructure DNS management.

Co-authored-by: Hanzo Dev <[email protected]>
2026-02-10 18:13:23 +07:00

51 lines
1.0 KiB
Go

package auth
import (
"net/http"
"time"
"github.com/golang-jwt/jwt/v5"
"golang.org/x/crypto/bcrypt"
)
const (
CookieName = "jwt"
TokenExpiry = 24 * time.Hour
)
func VerifyPassword(password string, hash []byte) bool {
return bcrypt.CompareHashAndPassword(hash, []byte(password)) == nil
}
func GenerateToken(secret []byte) (string, error) {
claims := jwt.MapClaims{
"authenticated": true,
"exp": time.Now().Add(TokenExpiry).Unix(),
"iat": time.Now().Unix(),
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString(secret)
}
func SetCookie(w http.ResponseWriter, tokenString string) {
http.SetCookie(w, &http.Cookie{
Name: CookieName,
Value: tokenString,
Path: "/",
HttpOnly: true,
SameSite: http.SameSiteStrictMode,
MaxAge: int(TokenExpiry.Seconds()),
})
}
func ClearCookie(w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{
Name: CookieName,
Value: "",
Path: "/",
HttpOnly: true,
SameSite: http.SameSiteStrictMode,
MaxAge: -1,
})
}