1// Copyright 2018 Frédéric Guillot. All rights reserved. 2// Use of this source code is governed by the Apache 2.0 3// license that can be found in the LICENSE file. 4 5package cli // import "miniflux.app/cli" 6 7import ( 8 "bufio" 9 "fmt" 10 "os" 11 "strings" 12 13 "golang.org/x/crypto/ssh/terminal" 14) 15 16func askCredentials() (string, string) { 17 fd := int(os.Stdin.Fd()) 18 19 if !terminal.IsTerminal(fd) { 20 fmt.Fprintf(os.Stderr, "This is not a terminal, exiting.\n") 21 os.Exit(1) 22 } 23 24 fmt.Print("Enter Username: ") 25 26 reader := bufio.NewReader(os.Stdin) 27 username, _ := reader.ReadString('\n') 28 29 fmt.Print("Enter Password: ") 30 31 state, _ := terminal.GetState(fd) 32 defer terminal.Restore(fd, state) 33 bytePassword, _ := terminal.ReadPassword(fd) 34 35 fmt.Printf("\n") 36 return strings.TrimSpace(username), strings.TrimSpace(string(bytePassword)) 37} 38