ask_credentials.go 826 B

12345678910111213141516171819202122232425262728293031323334353637
  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. package cli // import "miniflux.app/cli"
  5. import (
  6. "bufio"
  7. "fmt"
  8. "os"
  9. "strings"
  10. "golang.org/x/crypto/ssh/terminal"
  11. )
  12. func askCredentials() (string, string) {
  13. fd := int(os.Stdin.Fd())
  14. if !terminal.IsTerminal(fd) {
  15. fmt.Fprintf(os.Stderr, "This is not a terminal, exiting.\n")
  16. os.Exit(1)
  17. }
  18. fmt.Print("Enter Username: ")
  19. reader := bufio.NewReader(os.Stdin)
  20. username, _ := reader.ReadString('\n')
  21. fmt.Print("Enter Password: ")
  22. state, _ := terminal.GetState(fd)
  23. defer terminal.Restore(fd, state)
  24. bytePassword, _ := terminal.ReadPassword(fd)
  25. fmt.Printf("\n")
  26. return strings.TrimSpace(username), strings.TrimSpace(string(bytePassword))
  27. }