当前位置: 首页>>代码示例>>Golang>>正文


Golang Terminal.ReadPassword方法代码示例

本文整理汇总了Golang中golang.org/x/crypto/ssh/terminal.Terminal.ReadPassword方法的典型用法代码示例。如果您正苦于以下问题:Golang Terminal.ReadPassword方法的具体用法?Golang Terminal.ReadPassword怎么用?Golang Terminal.ReadPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在golang.org/x/crypto/ssh/terminal.Terminal的用法示例。


在下文中一共展示了Terminal.ReadPassword方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: promptForForm


//.........这里部分代码省略.........
					// This is a oddity of jabber.ccc.de and maybe
					// others. The URL for the capture is provided
					// as the default answer to a question. Perhaps
					// that was needed with some clients. However,
					// we support embedded media and it's confusing
					// to ask the question, so we just print the
					// URL.
					write(fmt.Sprintf("CAPTCHA web page (only if not provided below): %s\n", formStringForPrinting(field.Default)))
					questionNumber--
					continue
				}

			case "User":
				field.Result = user
				questionNumber--
				continue

			case "Password":
				field.Result = password
				questionNumber--
				continue
			}

			write(fmt.Sprintf("%d. %s\n\n", questionNumber, formStringForPrinting(field.Label)))
			showMediaEntries(questionNumber, field.Media)

			if len(field.Default) > 0 {
				write(fmt.Sprintf("Please enter response or leave blank for the default, which is '%s'\n", formStringForPrinting(field.Default)))
			} else {
				write("Please enter response")
			}
			term.SetPrompt("> ")
			if field.Private {
				field.Result, err = term.ReadPassword("> ")
			} else {
				field.Result, err = term.ReadLine()
			}
			if err != nil {
				return err
			}
			if len(field.Result) == 0 {
				field.Result = field.Default
			}

		case *xmpp.MultiTextFormField:
			write(fmt.Sprintf("%d. %s\n\n", questionNumber, formStringForPrinting(field.Label)))
			showMediaEntries(questionNumber, field.Media)

			write("Please enter one or more responses, terminated by an empty line\n")
			term.SetPrompt("> ")

			for {
				line, err := term.ReadLine()
				if err != nil {
					return err
				}
				if len(line) == 0 {
					break
				}
				field.Results = append(field.Results, line)
			}

		case *xmpp.SelectionFormField:
			write(fmt.Sprintf("%d. %s\n\n", questionNumber, formStringForPrinting(field.Label)))
			showMediaEntries(questionNumber, field.Media)
开发者ID:PMaynard,项目名称:coyim,代码行数:66,代码来源:ui.go

示例2: main

func main() {
	var (
		filename string
		site     string
		username string
		password string
		line     string
		buf      []byte
		db       *keyrack.Database
		oldState *terminal.State
		term     *terminal.Terminal
		termio   TermIO
		group    *keyrack.Group
		//trail     []*keyrack.Group
		groupView GroupView
		matched   bool
		quit      bool
		err       error
	)

	if len(os.Args) != 2 {
		fmt.Printf("Syntax: %s <filename>\n", os.Args[0])
		os.Exit(1)
	}
	filename = os.Args[1]

	// setup terminal
	oldState, err = terminal.MakeRaw(0)
	if err != nil {
		panic(err)
	}
	defer terminal.Restore(0, oldState)

	termio.Input = os.Stdin
	termio.Output = os.Stdout
	term = terminal.NewTerminal(termio, "> ")

	if _, err = os.Stat(filename); os.IsNotExist(err) {
		db, err = keyrack.NewDatabase()
	} else {
		password, err = term.ReadPassword("Password: ")
		if err == nil {
			db, err = keyrack.LoadDatabase(filename, []byte(password))
		}
		password = ""
	}

	group = db.Top()
	for err == nil && !quit {
		groupView.Group = group
		buf, err = groupView.Render()
		if err != nil {
			break
		}

		_, err = term.Write(buf)
		if err != nil {
			break
		}

		line, err = term.ReadLine()
		if err != nil {
			break
		}

		switch line {
		case "q":
			password, err = term.ReadPassword("Password: ")
			if err == nil {
				err = db.Save(filename, []byte(password))
			}
			password = ""
			quit = true
		case "ng", "new group":
			term.SetPrompt("Group name: ")
			line, err = term.ReadLine()
			if err != nil {
				break
			}

			if line == "" {
				term.Write([]byte("Group creation cancelled.\n"))
			} else {
				err = group.AddGroup(line)
				if err != nil {
					if err == keyrack.ErrGroupExists {
						term.Write([]byte("Group already exists.\n"))
					} else {
						break
					}
				}
			}
			term.SetPrompt("> ")
		case "nl", "new login":
			term.SetPrompt("Site name: ")
			site, err = term.ReadLine()
			if err != nil {
				break
			}

//.........这里部分代码省略.........
开发者ID:viking,项目名称:go-keyrack,代码行数:101,代码来源:main.go


注:本文中的golang.org/x/crypto/ssh/terminal.Terminal.ReadPassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。