<commit_before>package main

import (
	"crypto/sha512"
	"encoding/base64"
	"fmt"
	"io"
	"log"
	"net/http"
	"strings"
)

// during alpha, we use basic auth for alpha access
// basic auth is chosen because it does not interfere with any other techniques used by this project
// the alphaUsers map holds all alpha users and their sha512 hashed passwords.
// the password is to be salted with the alphaSalt (e.g. <password>+alphaSalt)
// feel free to add yourself or other project members to the map
var alphaSalt = "che9ohlu0xie9yaW6aeg"
var alphaUsers = map[string]string{
	"GeertJohan": "<KEY>",
}

func alphaCheckBasicAuth(r *http.Request) bool {
	// retrieve auth header
	authHeader := r.Header.Get("Authorization")
	if len(authHeader) < 7 {
		// no or invalid auth given
		return false
	}
	if authHeader[:6] != "Basic " {
		// invalid auth type
		return false
	}

	// decode auth data
	authData, err := base64.StdEncoding.DecodeString(authHeader[6:])
	if err != nil {
		log.Printf("Could not decode auth. %s\n", err)
		return false
	}
	authDataSlice := strings.SplitN(string(authData), ":", 2)
	givenUsername := authDataSlice[0]
	givenPassword := authDataSlice[1]

	// retrieved hashed password from alphaUsers map
	correctPasswordHashed, userExists := alphaUsers[givenUsername]
	if !userExists {
		// user does not exist
		return false
	}
	log.Println("user exists. hash is: ")
	log.Println(correctPasswordHashed)

	// hash retrieved password, format as hex string
	passwordHasher := sha512.New()
	io.WriteString(passwordHasher, givenPassword)
	io.WriteString(passwordHasher, alphaSalt)
	givenPasswordHashed := fmt.Sprintf("%x", passwordHasher.Sum(nil))
	log.Println(givenPasswordHashed)
	// password matches?
	if givenPasswordHashed == correctPasswordHashed {
		// yay! correct auth!
		log.Println("correct auth")
		return true
	}

	return false
}<commit_msg>Removed logging from alpha.go Added extra check on base auth correctness<commit_after>package main

import (
	"crypto/sha512"
	"encoding/base64"
	"fmt"
	"io"
	"net/http"
	"strings"
)

// during alpha, we use basic auth for alpha access
// basic auth is chosen because it does not interfere with any other techniques used by this project
// the alphaUsers map holds all alpha users and their sha512 hashed passwords.
// the password is to be salted with the alphaSalt (e.g. <password>+alphaSalt)
// feel free to add yourself or other project members to the map
var alphaSalt = "<PASSWORD>"
var alphaUsers = map[string]string{
	"GeertJohan": "<KEY>",
}

func alphaCheckBasicAuth(r *http.Request) bool {
	// retrieve auth header
	authHeader := r.Header.Get("Authorization")
	if len(authHeader) < 7 {
		// no or invalid auth given
		return false
	}
	if authHeader[:6] != "Basic " {
		// invalid auth type
		return false
	}

	// decode auth data
	authData, err := base64.StdEncoding.DecodeString(authHeader[6:])
	if err != nil {
		return false
	}
	authDataSlice := strings.SplitN(string(authData), ":", 2)
	if len(authDataSlice) != 2 {
		return false
	}
	givenUsername := authDataSlice[0]
	givenPassword := authDataSlice[1]

	// retrieved hashed password from alphaUsers map
	correctPasswordHashed, userExists := alphaUsers[givenUsername]
	if !userExists {
		// user does not exist
		return false
	}

	// hash retrieved password, format as hex string
	passwordHasher := sha512.New()
	io.WriteString(passwordHasher, givenPassword)
	io.WriteString(passwordHasher, alphaSalt)
	givenPasswordHashed := fmt.Sprintf("%x", passwordHasher.Sum(nil))
	// password matches?
	if givenPasswordHashed == correctPasswordHashed {
		// yay! correct auth!
		return true
	}

	return false
}
{'fraction_non_alphanumeric': 0.10749724366041896, 'fraction_numerical': 0.011852260198456449, 'mean_word_length': 4.290087463556851, 'pattern_counts': {'":': 4, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3599547', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1130, 'n_words': 366}