ask_credentials.go 764 B

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package cli // import "miniflux.app/v2/internal/cli"
  4. import (
  5. "bufio"
  6. "fmt"
  7. "os"
  8. "strings"
  9. "golang.org/x/term"
  10. )
  11. func askCredentials() (string, string) {
  12. fd := int(os.Stdin.Fd())
  13. if !term.IsTerminal(fd) {
  14. printErrorAndExit(fmt.Errorf("this is not an interactive terminal, exiting"))
  15. }
  16. fmt.Print("Enter Username: ")
  17. reader := bufio.NewReader(os.Stdin)
  18. username, _ := reader.ReadString('\n')
  19. fmt.Print("Enter Password: ")
  20. state, _ := term.GetState(fd)
  21. defer term.Restore(fd, state)
  22. bytePassword, _ := term.ReadPassword(fd)
  23. fmt.Printf("\n")
  24. return strings.TrimSpace(username), strings.TrimSpace(string(bytePassword))
  25. }