<commit_before>// +build freebsd openbsd netbsd darwin linux

package gopass

/*
#include <termios.h>
#include <unistd.h>
#include <stdio.h>

int getch() {
        int ch;
        struct termios t_old, t_new;

        tcgetattr(STDIN_FILENO, &t_old);
        t_new = t_old;
        t_new.c_lflag &= ~(ICANON | ECHO);
        tcsetattr(STDIN_FILENO, TCSANOW, &t_new);

        ch = getchar();

        tcsetattr(STDIN_FILENO, TCSANOW, &t_old);
        return ch;
}
*/
import "C"

func getch() byte {
	return byte(C.getch())
}

// Returns password byte array read from terminal without input being echoed.
// Array of bytes does not include end-of-line characters.
func GetPasswd() []byte {
	pass := make([]byte, 0)
	for v := getch(); ; v = getch() {
		if v == 127 || v == 8 {
			if len(pass) > 0 {
				pass = pass[:len(pass)-1]
			}<commit_msg>Added password masking using * as mask<commit_after>// +build freebsd openbsd netbsd darwin linux

package gopass

/*
#include <termios.h>
#include <unistd.h>
#include <stdio.h>

int getch() {
        int ch;
        struct termios t_old, t_new;

        tcgetattr(STDIN_FILENO, &t_old);
        t_new = t_old;
        t_new.c_lflag &= ~(ICANON | ECHO);
        tcsetattr(STDIN_FILENO, TCSANOW, &t_new);

        ch = getchar();

        tcsetattr(STDIN_FILENO, TCSANOW, &t_old);
        return ch;
}
*/
import "C"
import "fmt"
import "os"

var secret = make([]byte, 0)
var mask = byte('*')

func getch() (password byte) {
	password = byte(C.getch())

	// Includes spaces A-Z a-z and special characters
	// Delete * if backspace pressed
	// TODO: Not allow spaces?
	if password >= 32 && password <= 126 {
		secret = append(secret, mask)
		fmt.Print(string(mask))
	} else if password == <PASSWORD> || password == 8 {
		if len(secret) > 0 {
			secret = secret[:len(secret)-1]
			os.Stdin.Write([]byte("\b \b"))
		}
	}
	return
}

// Returns password byte array read from terminal without input being echoed.
// Array of bytes does not include end-of-line characters.
func GetPasswd() []byte {
	pass := make([]byte, 0)
	for v := getch(); ; v = getch() {
		if v == 127 || v == 8 {
			if len(pass) > 0 {
				pass = pass[:len(pass)-1]
			}
{'fraction_non_alphanumeric': 0.1489655172413793, 'fraction_numerical': 0.010574712643678161, 'mean_word_length': 2.8445229681978796, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, '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': '4339104', 'n_tokens_mistral': 868, 'n_tokens_neox': 788, 'n_words': 229}