go - 编写 CLI : How to avoid showing the typed password on screen

标签 go command-line-interface

<分区>

我正在使用 Go 编写命令行工具,其中一个命令将查询用户的用户名和密码(并将其保存到主目录内的配置文件中)。

目前我还不知道如何将键入的密码替换为“*”,甚至无法像许多命令行工具那样不键入任何内容。

在使用 golang 时如何做到这一点?

最佳答案

在你来这里之前把这些东西输入谷歌。

you can do this by execing stty -echo to turn off echo and then stty echo after reading in the password to turn it back on

Just saw a mail in #go-nuts maillist. There is someone who wrote quite a simple go package to be used. You can find it here: https://github.com/howeyc/gopass

It something like that:

package main

import "fmt" import "github.com/howeyc/gopass"

func main() {
    fmt.Printf("Password: ")
    pass := gopass.GetPasswd()
    // Do something with pass }

Taken from another Stackoverflow post.

关于go - 编写 CLI : How to avoid showing the typed password on screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33237126/

相关文章:

linux - 在 Whatsapp 中查看图像元数据

android - 为 Android 部署 Phonegap/Cordova 应用程序?

java - getQauntdate()方法解释

go - 如何使用 Stdin 获取输入并等待 Golang 的 Stdin 中有新数据

go function input, func (req *AppendEntriesRequest) 编码(w io.Writer) (int, error) {

go - 如何从失败的命令中读取标准输出

go - Go中 slice 的最大长度

linux - arm 上的 autocert 中缺少字段或方法签名方案

command-line-interface - asterisk cli 命令 "channel originate"以及通话持续时间或长度

python - Sublime Text 2 - 无法运行带有空格和引号的 Windows 命令