func BasicAuth(h fasthttp.RequestHandler, requiredUser string, requiredPasswordHash []byte) fasthttp.RequestHandler {
	return func(ctx *fasthttp.RequestCtx) {
		user, password, hasAuth := basicAuth(ctx)
		if hasAuth && user == requiredUser {
			err := scrypt.CompareHashAndPassword(requiredPasswordHash, []byte(password))
			if err != nil {
				log.Fatal(err)
			} else {
				h(ctx)
				return
			}
		}
		ctx.Error(fasthttp.StatusMessage(fasthttp.StatusUnauthorized), fasthttp.StatusUnauthorized)
		ctx.Response.Header.Set("WWW-Authenticate", "Basic realm=Restricted")
	}
}
BasicAuth is the basic auth handler
package main
import (
	"encoding/base64"
	"fmt"
	"log"
	"strings"
	scrypt "github.com/elithrar/simple-scrypt"
	"github.com/fasthttp/router"
	"github.com/valyala/fasthttp"
)
func basicAuth(ctx *fasthttp.RequestCtx) (username, password string, ok bool) {
	auth := ctx.Request.Header.Peek("Authorization")
	if auth == nil {
		return
	}
	return parseBasicAuth(string(auth))
}
func parseBasicAuth(auth string) (username, password string, ok bool) {
	const prefix = "Basic "
	if !strings.HasPrefix(auth, prefix) {
		return
	}
	c, err := base64.StdEncoding.DecodeString(auth[len(prefix):])
	if err != nil {
		return
	}
	cs := string(c)
	s := strings.IndexByte(cs, ':')
	if s < 0 {
		return
	}
	return cs[:s], cs[s+1:], true
}