本文整理匯總了Golang中github.com/howeyc/gopass.GetPasswd函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetPasswd函數的具體用法?Golang GetPasswd怎麽用?Golang GetPasswd使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetPasswd函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: InsertFunc
func InsertFunc(args Args) {
PrepareFile()
fmt.Println("Inserting a new password record")
rec := PasssRecord{}
promt("Website: ")
fmt.Scanln(&rec.Website)
promt("Username: ")
fmt.Scanln(&rec.Username)
for {
promt("Password: ")
pwd := string(gopass.GetPasswd())
promt("Repeat: ")
pwd2 := string(gopass.GetPasswd())
if pwd == pwd2 {
rec.Password = pwd
break
} else {
fmt.Println("Entered passwords are different! Please try again.")
}
}
fmt.Println("Inserted a new record:")
rec.PrintHead()
Records = append(Records, rec)
EncryptAndSave()
}
示例2: getPassword
func getPassword() (password string) {
fmt.Println("Password: ")
pwd, err := gopass.GetPasswd()
if err != nil {
fmt.Errorf("Error: %s", err)
return getPassword()
}
password = string(pwd)
if string(pwd) == "" {
fmt.Println("You did not provide a password. Please try again.")
return getPassword()
}
fmt.Println("Confirm password: ")
confirm, err := gopass.GetPasswd()
if err != nil {
fmt.Errorf("Error: %s", err)
return getPassword()
}
if password != string(confirm) {
fmt.Println("Password and confirmation do not match. Please try again.")
return getPassword()
}
return
}
示例3: askForPassword
func askForPassword(confirm bool) (password []byte, err error) {
for {
fmt.Printf("Enter passphrase: ")
password = gopass.GetPasswd()
if err != nil {
return
}
if !confirm {
break
}
var confirmation []byte
fmt.Printf("Confirm passphrase: ")
confirmation = gopass.GetPasswd()
if err != nil {
return
}
if len(password) == 0 {
fmt.Println("Empty password, please try again.")
clearBytes(confirmation)
continue
}
if bytes.Equal(password, confirmation) {
clearBytes(confirmation)
break
}
fmt.Println("Passphrases mismatch, please try again.")
clearBytes(confirmation)
clearBytes(password)
}
return
}
示例4: addDBUser
func addDBUser() {
reader := bufio.NewReader(os.Stdin)
name := ask(reader, "Name: ")
email := ask(reader, "Email ")
if !IsEmail(email) {
Log.Fatalf("%s is not a valid email address.", email)
}
fmt.Print("Password: ")
pass := gopass.GetPasswd()
fmt.Print("Confirm: ")
cpass := gopass.GetPasswd()
if string(pass) != string(cpass) {
Log.Fatal("Password and confirm do not match.")
}
user := &UserDb{
Name: name,
Email: email,
Password: string(pass),
}
err := CreateUser(user)
if err != nil {
Log.Fatal(err)
}
Log.Info("User created successfully.")
}
示例5: main
func main() {
var err error
flag.Parse()
state := shares.State{
StorageDir: StorageDir,
}
DatabaseDir := filepath.Join(StorageDir, "db")
state.Database, err = shares.NewDatabase(DatabaseDir)
if err != nil {
log.Printf("unable to open database: %s", err)
os.Exit(1)
}
name := flag.Arg(0)
if name == "" {
log.Printf("no user given")
os.Exit(1)
}
user, err := state.User(name)
if err == nil {
fmt.Printf("Loaded user %s\n", name)
} else if create == true {
user = state.NewUser(name)
fmt.Printf("created new user: %s\n", name)
} else {
fmt.Printf("unknown user: %s\n", name)
return
}
if chpasswd == true {
fmt.Printf("Enter current password:")
curPass := gopass.GetPasswd()
fmt.Printf("Enter new password:")
newPass := gopass.GetPasswd()
fmt.Printf("Enter new password again:")
if another := gopass.GetPasswd(); string(newPass) != string(another) {
fmt.Printf("new passwords did not match\n")
return
}
if !user.SetPassword(string(curPass), string(newPass)) {
fmt.Printf("failed to set password for new user")
return
}
fmt.Printf("successfully set new password for user %s\n", name)
}
if err = user.Save(); err != nil {
fmt.Printf("failed to save user after creation: %s\n", err)
return
}
}
示例6: getPassword
func getPassword() (password string) {
fmt.Println("Password: ")
password = string(gopass.GetPasswd())
if password == "" {
fmt.Println("You did not provide a password. Please try again.")
return getPassword()
}
fmt.Println("Confirm password: ")
if password != string(gopass.GetPasswd()) {
fmt.Println("Password and confirmation do not match. Please try again.")
return getPassword()
}
return
}
示例7: loginAction
func loginAction(c *cli.Context) {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("URL: ")
ur, err := reader.ReadString('\n')
if err != nil {
logger.Fatal(err)
}
fmt.Printf("Username: ")
u, err := reader.ReadString('\n')
if err != nil {
logger.Fatal(err)
}
fmt.Printf("Password: ")
p := gopass.GetPasswd()
sUrl := strings.TrimSpace(string(ur[:]))
username := strings.TrimSpace(string(u[:]))
pass := strings.TrimSpace(string(p[:]))
cfg := &client.ShipyardConfig{
Url: sUrl,
Username: username,
}
m := client.NewManager(cfg)
token, err := m.Login(username, pass)
if err != nil {
logger.Fatal(err)
}
cfg.Token = token.Token
if err := saveConfig(cfg); err != nil {
logger.Fatal(err)
}
}
示例8: main
func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "Usage: genconfig <output.json>")
os.Exit(1)
}
var c Config
fmt.Print("Admin password: ")
pass := gopass.GetPasswd()
hash := sha256.Sum256([]byte(pass))
c.AdminHash = strings.ToLower(hex.EncodeToString(hash[:]))
c.ClientID = promptInput("FB App ID: ")
c.Secret = promptInput("FB Secret: ")
c.CallbackURI = promptInput("Landing URL (e.g. http://foo.com): ") + "/fblogin_done"
for {
tz := promptInput("Time zone (e.g. UTC, America/New_York): ")
if _, err := time.LoadLocation(tz); err != nil {
fmt.Println("Invalid time zone")
} else {
c.Timezone = tz
break
}
}
data, _ := json.Marshal(&c)
if err := ioutil.WriteFile(os.Args[1], data, 0700); err != nil {
fmt.Fprintln(os.Stderr, "Failed to write output:", err)
os.Exit(1)
}
}
示例9: getPasswd
func getPasswd() string {
p, err := gopass.GetPasswd()
if err != nil {
panic(err)
}
return string(p)
}
示例10: authorize
// Reads oauth tokens from disk if exist, else prompt for login
func authorize(force bool) {
conf, err := getRc()
client, err = api.NewPKClient(conf.URL)
if force || err != nil {
var username, password string
fmt.Printf("Email: ")
fmt.Scanln(&username)
fmt.Printf("Password: ")
password = string(gopass.GetPasswd())
err = client.Authorize(username, password) // should return json on unauthorized
if err != nil {
fmt.Println("Authorization error:", err)
return
}
conf.User = username
conf.AccessToken = client.AccessToken
conf.Expiration = client.TokenExpiration
if err := conf.saveRc(); err != nil {
panic(err)
}
} else {
client.AccessToken = conf.AccessToken
client.TokenExpiration = conf.Expiration
}
return
}
示例11: serverCommand
func serverCommand() cli.Command {
return cli.Command{
Name: "server",
Usage: "Run webservice",
Flags: serverFlags(),
Action: func(c *cli.Context) {
db_user := c.String("database-user")
db_host := c.String("database-host")
db := c.String("database")
fmt.Printf("%[email protected]%s/%s password: ", db_user, db_host, db)
db_pass, _ := gopass.GetPasswd()
ds, err := atm.NewDatastore("mysql", fmt.Sprintf("%s:%[email protected](%s:%d)/%s",
db_user, string(db_pass), db_host, c.Int("database-port"), db))
if nil != err {
log.Fatal(err)
return
}
db_pass = []byte("")
defer ds.Close()
service := &atm.Server{
Ds: ds,
Object_host: c.String("object-host"),
Default_duration: int64(c.Duration("duration").Seconds()),
Nonces: atm.NewNonceStore(),
}
service.Run()
},
}
}
示例12: ReadPassword
// ReadPassword reads password from standard input without echoing the characters.
// If mask is true, each chracter will be represented with astericks '*'. Note that
// this only works as expected when the standard input is a terminal.
func (s *Shell) ReadPassword(mask bool) string {
fmt.Fprint(s.writer, s.prompt)
if mask {
return string(gopass.GetPasswdMasked())
}
return string(gopass.GetPasswd())
}
示例13: GetPass
func GetPass() string {
if data, errData := gopass.GetPasswd(); errData != nil {
return ``
} else {
return string(data)
}
}
示例14: DialInConsole
//TODO 某種認證方法隻有一個會被使用,需要多次猜測
func DialInConsole(addr string, username string) (client *ssh.Client, err error) {
//find cert file
pathList := certFilePathList()
authList := []ssh.AuthMethod{}
for _, path := range pathList {
clientKeyBytes, err := ioutil.ReadFile(path)
if err != nil {
if !os.IsNotExist(err) {
return nil, fmt.Errorf("[DialInConsole] ioutil.ReadFile() err:%s", err)
}
} else {
signer, err := ssh.ParsePrivateKey(clientKeyBytes)
if err != nil {
return nil, fmt.Errorf("[DialInConsole] ssh.ParsePrivateKey err:%s", err)
}
//clientKey := &keychain{signer}
authList = append(authList, ssh.PublicKeys(signer))
}
}
authList = append(authList, ssh.PasswordCallback(func() (secret string, err error) {
fmt.Printf("[ssh] password for %[email protected]%s", username, addr)
secret = string(gopass.GetPasswd())
return
}))
clientConfig := &ssh.ClientConfig{
User: username,
Auth: authList,
}
client, err = ssh.Dial("tcp", addr, clientConfig)
if err != nil {
return nil, fmt.Errorf("[DialInConsole] Failed to dial: %s", err.Error())
}
return
}
示例15: main
func main() {
turnpike.Debug()
fmt.Println("Hint: the password is 'password'")
fmt.Print("Password: ")
var err error
password, err = gopass.GetPasswd()
if err != nil {
log.Fatal("Error getting the password:", err)
}
c, err := turnpike.NewWebsocketClient(turnpike.JSON, "ws://localhost:8000/ws", nil)
if err != nil {
log.Fatal(err)
}
c.Auth = map[string]turnpike.AuthFunc{"example-auth": exampleAuthFunc}
_, err = c.JoinRealm("turnpike.examples", nil)
if err != nil {
log.Fatal(err)
}
fmt.Println("Connected with auth")
time.Sleep(3 * time.Second)
fmt.Println("Disconnecting")
c.Close()
}