<commit_before>/*
Package authentication implements a very minimal (and incomplete) HTTP Basic Auth
verification mechanism.

It includes a proof of concept of a credentials store, which should be taken
as it is - just a demo.
*/
package authentication

import (
	"encoding/base64"
	"log"
	"strings"
)

// The possible statuses of authentication process
const (
	_ = iota
	NotAttempted
	NotBasic
	Failed
	Passed
)

// This is just a proof of concept. Not for production use!
var poorMansCredentialStore = map[string]string{
	"foo": "bar",
	"baz": "boo",
}

// BasicAuthPassed verifies an authHeader to see if it passed HTTP Basic Auth.
func BasicAuthPassed(authHeader string) (status int, user string) {
	if authHeader == "" {
		return NotAttempted, user
	}

	tokens := strings.Split(authHeader, " ")
	method, token := tokens[0], tokens[1]
	if method != "Basic" {
		return NotBasic, user
	}

	data, err := base64.StdEncoding.DecodeString(token)
	if err != nil {
		log.Println(err)
		return Failed, user
	}

	tokens = strings.Split(string(data), ":")
	user, pass := tokens[0], tokens[1]

	if poorMansCredentialStore[user] == pass {
		return Passed, user
	} else {
		return Failed, user
	}
}<commit_msg>Making golint happy<commit_after>/*
Package authentication implements a very minimal (and incomplete) HTTP Basic Auth
verification mechanism.

It includes a proof of concept of a credentials store, which should be taken
as it is - just a demo.
*/
package authentication

import (
	"encoding/base64"
	"log"
	"strings"
)

// The possible statuses of authentication process
const (
	_ = iota
	NotAttempted
	NotBasic
	Failed
	Passed
)

// This is just a proof of concept. Not for production use!
var poorMansCredentialStore = map[string]string{
	"foo": "bar",
	"baz": "boo",
}

// BasicAuthPassed verifies an authHeader to see if it passed HTTP Basic Auth.
func BasicAuthPassed(authHeader string) (status int, user string) {
	if authHeader == "" {
		return NotAttempted, user
	}

	tokens := strings.Split(authHeader, " ")
	method, token := tokens[0], tokens[1]
	if method != "Basic" {
		return NotBasic, user
	}

	data, err := base64.StdEncoding.DecodeString(token)
	if err != nil {
		log.Println(err)
		return Failed, user
	}

	tokens = strings.Split(string(data), ":")
	user, pass := tokens[0], tokens[1]

	if poorMansCredentialStore[user] == pass {
		return Passed, user
	}
	return Failed, user
}
{'fraction_non_alphanumeric': 0.10855949895615867, 'fraction_numerical': 0.006680584551148226, 'mean_word_length': 4.163793103448276, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '3200138', 'n_tokens_mistral': 801, 'n_tokens_neox': 763, 'n_words': 265}