<commit_before>package user

import (
	"fmt"
	"log"
	"net/http"
	"net/http/httptest"
	"syscall"

	"github.com/cswank/quimby/internal/auth"
	"github.com/cswank/quimby/internal/repository"
	"golang.org/x/crypto/ssh/terminal"
)

func Create(r *repository.User, username string) error {
	fmt.Print("Enter Password: ")
	pw, err := terminal.ReadPassword(int(syscall.Stdin))
	if err != nil {
		return err
	}

	pw, tfa, qa, err := auth.Credentials(username, string(pw))
	if err != nil {
		return err
	}

	u, err := r.Create(username, pw, tfa)
	if err != nil {
		return err
	}

	h := func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		w.Header().Set("Content-Type", "application/octet-stream")
		w.Write(qa)
	}

	ts := httptest.NewServer(http.HandlerFunc(h))

	fmt.Printf("\ncreated user: %d %s\n, open %s to scan code\n", u.ID, u.Name, ts.URL)
	fmt.Println("hit enter when done")

	var i int
	fmt.Scanln(&i)

	ts.Close()

	return nil
}

func Delete(r *repository.User, username string) {
	if err := r.Delete(username); err != nil {
		log.Fatal(err)
	}
}

func List(r *repository.User) {
	users, err := r.GetAll()
	if err != nil {
		log.Fatal(err)
	}

	for _, u := range users {
		fmt.Printf("%d: %s\n", u.ID, u.Name)
	}
}<commit_msg>confirm password<commit_after>package user

import (
	"bytes"
	"fmt"
	"log"
	"net/http"
	"net/http/httptest"
	"syscall"

	"github.com/cswank/quimby/internal/auth"
	"github.com/cswank/quimby/internal/repository"
	"golang.org/x/crypto/ssh/terminal"
)

func Create(r *repository.User, username string) {
	fmt.Print("Enter password: ")
	pw, err := terminal.ReadPassword(int(syscall.Stdin))
	if err != nil {
		log.Fatal(err)
	}

	fmt.Print("Confirm password: ")
	pw2, err := terminal.ReadPassword(int(syscall.Stdin))
	if err != nil {
		log.Fatal(err)
	}

	if !bytes.Equal(pw, pw2) {
		log.Fatal(fmt.Errorf("passwords don't match"))
	}

	hashed, tfa, qr, err := auth.Credentials(username, string(pw))
	if err != nil {
		log.Fatal(err)
	}

	u, err := r.Create(username, hashed, tfa)
	if err != nil {
		log.Fatal(err)
	}

	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		w.Header().Set("Content-Type", "application/octet-stream")
		w.Write(qr)
	}))

	fmt.Printf("\ncreated user: %d %s\n, open %s to scan code\n", u.ID, u.Name, ts.URL)
	fmt.Println("hit enter when done")

	var i int
	fmt.Scanln(&i)

	ts.Close()
}

func Delete(r *repository.User, username string) {
	if err := r.Delete(username); err != nil {
		log.Fatal(err)
	}
}

func List(r *repository.User) {
	users, err := r.GetAll()
	if err != nil {
		log.Fatal(err)
	}

	for _, u := range users {
		fmt.Printf("%d: %s\n", u.ID, u.Name)
	}
}
{'fraction_non_alphanumeric': 0.17837440235380655, 'fraction_numerical': 0.000735564545788893, 'mean_word_length': 3.7469458987783595, 'pattern_counts': {'":': 0, '<': 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': '7568196', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1100, 'n_words': 231}