Commits

Markus Tzoe  committed 7c95961

use libncurses for passwd input

  • Participants
  • Parent commits 0696b58

Comments (0)

Files changed (2)

+package main
+
+// #cgo LDFLAGS: -lncurses
+// #include <curses.h>
+// #include <stdio.h>
+// #include <stdlib.h>
+/*
+char* lgetstr() {
+    SCREEN* s = newterm(NULL, stdin, stdout);
+    if (s == NULL) return NULL;
+    noecho();
+    char* ret = malloc(sizeof(char) * 32);
+    getnstr(ret, 32);
+    endwin();
+    delscreen(s);
+    return ret;
+}
+*/
+import "C"
+import (
+    "fmt"
+    "unsafe"
+)
+
+func getpass() string {
+    fmt.Printf("Password: ")
+    a := C.lgetstr()
+    if a == (*C.char)(unsafe.Pointer(uintptr(0))) {
+        return ""
+    }
+    defer C.free(unsafe.Pointer(a))
+    fmt.Printf("\n")
+    return C.GoString(a)
+}
 package main
 
 import (
-	"bufio"
 	"crypto/md5"
 	"crypto/sha512"
 	"encoding/base64"
 	os.Exit(2)
 }
 
-func input(str string) string {
-	fmt.Printf("%s", str)
-	reader := bufio.NewReader(os.Stdin)
-	input, _ := reader.ReadString('\n')
-	return strings.TrimSpace(input)
-}
-
 func parseFlags() {
 	flag.Usage = usage
 	flag.Parse()
 	}
 	// password
 	if len(*flagPassword) <= 0 {
-		(*flagPassword) = input("Password: ")
+		(*flagPassword) = getpass()
 		if len(*flagPassword) <= 0 {
 			usage()
 		}