• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang gopass.GetPass函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中code/google/com/p/gopass.GetPass函数的典型用法代码示例。如果您正苦于以下问题:Golang GetPass函数的具体用法?Golang GetPass怎么用?Golang GetPass使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: main

func main() {
	t, err := pam.StartFunc("", "", func(s pam.Style, msg string) (string, error) {
		switch s {
		case pam.PromptEchoOff:
			return gopass.GetPass(msg)
		case pam.PromptEchoOn:
			fmt.Print(msg + " ")
			input, err := bufio.NewReader(os.Stdin).ReadString('\n')
			if err != nil {
				return "", err
			}
			return input[:len(input)-1], nil
		case pam.ErrorMsg:
			log.Print(msg)
			return "", nil
		case pam.TextInfo:
			fmt.Println(msg)
			return "", nil
		}
		return "", errors.New("Unrecognized message style")
	})
	if err != nil {
		log.Fatalf("Start: %s", err.Error())
	}
	err = t.Authenticate(0)
	if err != nil {
		log.Fatalf("Authenticate: %s", err.Error())
	}
	log.Print("Authentication succeeded!")
}
开发者ID:heimsphere,项目名称:pam,代码行数:30,代码来源:example.go


示例2: newMasterPass

func (s *PasswordStore) newMasterPass() error {

	pass1, err := gopass.GetPass("New Password for PasswordStore: ")
	if err != nil {
		return fmt.Errorf("Error in GetPass", err)
	}
	pass2, err := gopass.GetPass("Again: ")
	if err != nil {
		return fmt.Errorf("Error in GetPass", err)
	}

	if pass1 == pass2 {
		key, err := PaddingKey(pass1)
		if err != nil {
			return fmt.Errorf("Error in key creation", err)
		}
		cipher, err := encrypt(key, pass1)
		if err != nil {
			return fmt.Errorf("Error in encryption", err)
		}
		record1 := Newrecord("self", "", []byte(cipher))
		if err = s.Set(record1.Name, record1); err != nil {
			return fmt.Errorf("Error for self entry", err)
		}
	} else {
		return fmt.Errorf("Passwords doesn't match")
	}
	return nil
}
开发者ID:devsmt,项目名称:gpws,代码行数:29,代码来源:PasswordStore.go


示例3: changePassword

func changePassword(args []string) {
	if passwd == nil {
		pw, err := gopass.GetPass("   Current password: ")
		gobro.CheckErr(err)
		if pw == "" {
			fmt.Fprintln(os.Stderr, "Invalid password")
			return
		}
	}
	services, err := loadServices(getPasswd())
	gobro.CheckErr(err, "Password invalid")
	pw2, err := gopass.GetPass("   New Password: ")
	gobro.CheckErr(err)
	if pw2 == "" {
		fmt.Fprintln(os.Stderr, "Invalid password")
		return
	}
	pw3, err := gopass.GetPass("   Repeat Password: ")
	gobro.CheckErr(err)
	if pw3 == "" {
		fmt.Fprintln(os.Stderr, "Invalid password")
		return
	}
	if pw2 != pw3 {
		fmt.Fprintln(os.Stderr, "Passwords don't match")
		return
	}
	saveServices(pw2, services)
	passwd = &pw2
}
开发者ID:seanpont,项目名称:passman,代码行数:30,代码来源:passman.go


示例4: Input

func (s *Scanner) Input() string {
	passwd, err := gopass.GetPass(s.Ask)
	handleErr(err)
	if s.Validation {
		passwd_c, err := gopass.GetPass("Confirm: ")
		handleErr(err)
		if passwd != passwd_c {
			os.Exit(1)
		}
	}
	return passwd
}
开发者ID:niku4i,项目名称:mypwd,代码行数:12,代码来源:scan.go


示例5: getPassword

func getPassword(context *cli.Context) (password string, err error) {
	password = context.String("password")
	if len(password) > 0 {
		return password, nil
	}
	return gopass.GetPass("Plex password: ")
}
开发者ID:djeebus,项目名称:go-plexcast,代码行数:7,代码来源:cli.go


示例6: getUserJwt

func getUserJwt(userid string, baseUrl string, insecureSkipVerify bool) (*string, error) {

	if cachedToken := getCachedToken(); cachedToken != "" {
		return &cachedToken, nil
	}

	fmt.Fprintf(os.Stderr, "Enter password for "+userid+": ")
	pass, err := gopass.GetPass("")
	if err != nil {
		fmt.Println("*** No password provided ***")
		os.Exit(1)
	}
	url := baseUrl + "/auth/token"
	data := map[string]string{"userid": userid, "passwd": pass}
	body, code, err := DialHttp(url, "POST", data, "", "", insecureSkipVerify)
	if err != nil {
		return nil, err
	}
	if code == http.StatusOK {
		res := JwtResponse{}
		json.Unmarshal(body, &res)
		fmt.Println("Using token: " + res.Token)
		cacheToken(res.Token)
		return &res.Token, nil
	} else {
		err = fmt.Errorf("Invalid credentials")
		return nil, err
	}
}
开发者ID:prbinu,项目名称:spartan-go,代码行数:29,代码来源:main.go


示例7: ReadPrivateKey

// ReadPrivateKey attempts to read your private key and possibly decrypt it if it
// requires a passphrase.
// This function will prompt for a passphrase on STDIN if the environment variable (`IDENTITY_PASSPHRASE`),
// is not set.
func ReadPrivateKey(path string) ([]byte, error) {
	privateKey, err := ioutil.ReadFile(path)
	if err != nil {
		return nil, fmt.Errorf("failed to load identity: %v", err)
	}

	block, rest := pem.Decode(privateKey)
	if len(rest) > 0 {
		return nil, fmt.Errorf("extra data when decoding private key")
	}
	if !x509.IsEncryptedPEMBlock(block) {
		return privateKey, nil
	}

	passphrase := os.Getenv("IDENTITY_PASSPHRASE")
	if passphrase == "" {
		passphrase, err = gopass.GetPass("Enter passphrase: ")
		if err != nil {
			return nil, fmt.Errorf("couldn't read passphrase: %v", err)
		}
	}
	der, err := x509.DecryptPEMBlock(block, []byte(passphrase))
	if err != nil {
		return nil, fmt.Errorf("decrypt failed: %v", err)
	}

	privateKey = pem.EncodeToMemory(&pem.Block{
		Type:  block.Type,
		Bytes: der,
	})

	return privateKey, nil
}
开发者ID:dream1986,项目名称:ssh-chat,代码行数:37,代码来源:key.go


示例8: decryptPEM

func decryptPEM(pemblock *pem.Block, filename string) ([]byte, error) {
	var err error
	if _, err = fmt.Fprintf(os.Stderr, "Enter passphrase for %s: ", filename); err != nil {
		return []byte(""), err
	}

	// we already emit the prompt to stderr; GetPass only emits to stdout
	var passwd string
	passwd, err = gopass.GetPass("")
	fmt.Fprintln(os.Stderr, "")
	if err != nil {
		return []byte(""), err
	}

	var decryptedBytes []byte
	if decryptedBytes, err = x509.DecryptPEMBlock(pemblock, []byte(passwd)); err != nil {
		return []byte(""), err
	}

	pemBytes := pem.Block{
		Type:  "RSA PRIVATE KEY",
		Bytes: decryptedBytes,
	}
	decryptedPEM := pem.EncodeToMemory(&pemBytes)
	return decryptedPEM, nil
}
开发者ID:realestate-com-au,项目名称:credulous,代码行数:26,代码来源:credulous.go


示例9: main

func main() {
	if pw, err := keyring.Get("keyring_example", "jack"); err == nil {
		fmt.Println("current stored password:", pw)
	} else if err == keyring.ErrNotFound {
		fmt.Println("no password stored yet")
	} else {
		fmt.Println("got unexpected error:", err)
		os.Exit(1)
	}
	pw, err := gopass.GetPass("enter new password: ")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println("setting keyring_example/jack to..", pw)
	err = keyring.Set("keyring_example", "jack", pw)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println("fetching keyring_example/jack..")
	if pw, err := keyring.Get("keyring_example", "jack"); err == nil {
		fmt.Println("got", pw)
	} else {
		fmt.Println("error:", err)
	}
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:27,代码来源:example.go


示例10: Setup

func Setup(c *cli.Context) {
	client := github.Client{}
	user := Prompt("Username: ")

	password, err := gopass.GetPass("Password: ")
	if err != nil {
		log.Fatal(err)
	}

	token := ""
	if c.Bool("two-factor") {
		token = Prompt("Token: ")
	}

	client.BaseURL = c.String("url")

	generatedToken, err := client.CreateToken(user, password, token)
	if err != nil {
		log.Fatal(err)
	}

	client.Token = generatedToken.Token
	client.SaveConfig()

	os.Exit(0)
}
开发者ID:nlf,项目名称:gh,代码行数:26,代码来源:setup.go


示例11: AskForPass

// Hiding user text input requires a linux system using gopass.
func AskForPass() string {
	pass, err := gopass.GetPass("Enter passphrase> ")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	return pass
}
开发者ID:ngaut,项目名称:logbase,代码行数:9,代码来源:security.go


示例12: init

func init() {
	files := flag.String("f", "", "one or list of files")
	dir := flag.String("d", "", "dir with files")
	text := flag.String("t", "", "text")
	subject := flag.String("s", "", "subject")
	flag.Parse()

	if _, err := os.Stat(config); os.IsNotExist(err) {
		if _, err := os.Stat("~/.mailer.json"); os.IsNotExist(err) {
			config = "~/.mailer.json"
		}
	}
	conf, err := ioutil.ReadFile(config)
	if err != nil {
		fmt.Println("eror read " + config)
		fmt.Println(err.Error())
		usage()
	}
	err = json.Unmarshal(conf, &Conf)
	if err != nil {
		fmt.Println("eror read " + config)
		fmt.Println(err.Error())
		usage()
	}

	if len(flag.Args()) >= 1 {
		args := flag.Args()
		Conf.To = args[0]
	}

	//////

	if len(Conf.To) == 0 {
		usage()
	}

	if len(*files) > 0 {
		Conf.Attach = strings.Split(*files, ",")
	}

	if len(*dir) > 0 {
		Conf.Attach = []string{*dir}
	}

	if len(*text) > 0 {
		Conf.Text = *text
	}

	if len(*subject) > 0 {
		Conf.Subject = *subject
	}

	if len(Conf.Pass) == 0 {
		Conf.Pass, err = gopass.GetPass("pass:")
		checkerr(err)
	}

}
开发者ID:sg3des,项目名称:mailer,代码行数:58,代码来源:mailer.go


示例13: UserAdd

func UserAdd(args []string) {
	flags := flag.NewFlagSet("useradd", flag.ExitOnError)
	admin := flags.Bool("admin", false, "User should be an administrator")
	rpcSocket := flags.String("sock", rpcSocketDefault, rpcSocketDescription)
	flags.Parse(args)

	if flags.NArg() != 1 {
		fmt.Println("Error: please supply a username (and only one)")
		os.Exit(1)
	}

	passwordOne, err := gopass.GetPass("Enter password for new user: ")
	if err != nil {
		panic(err)
	}
	passwordTwo, err := gopass.GetPass("Enter the same password again: ")
	if err != nil {
		panic(err)
	}

	if passwordOne != passwordTwo {
		fmt.Println("Error: Passwords do not match. Please try again.")
		os.Exit(1)
	}

	user := new(User)

	if *admin {
		user.Role = ADMIN
	} else {
		user.Role = NORMAL
	}
	user.Username = flags.Arg(0)
	user.PWHash = HashPassword(passwordOne)

	i := 99
	err = asink.RPCCall(*rpcSocket, "UserModifier.AddUser", user, &i)
	if err != nil {
		if _, ok := err.(rpc.ServerError); ok && err.Error() == DuplicateUsernameErr.Error() {
			fmt.Println("Error: " + err.Error())
			return
		}
		panic(err)
	}
}
开发者ID:vichetuc,项目名称:asink,代码行数:45,代码来源:user_admin.go


示例14: main

func main() {
	password, err := gopass.GetPass("Enter password to be hashed: ")
	if err != nil {
		error("Could not read password:", err)
	}
	confirmation, err := gopass.GetPass("Repeat password: ")
	if err != nil {
		error("Could not read password:", err)
	}
	if password != confirmation {
		error("Passwords do not match.")
	}
	hash, err := bcrypt.GenerateFromPassword([]byte(password), 0)
	if err != nil {
		error("Could not hash password:", err)
	}
	fmt.Printf("%s\n", hash)
}
开发者ID:Ali-Kabiri,项目名称:monsti,代码行数:18,代码来源:bcrypt.go


示例15: Password

func (c *SSHConn) Password(user string) (string, error) {
	pass, err := gopass.GetPass("Password for " + user + ": ")

	if err != nil {
		return "", errors.New("Failed to collect password: " + err.Error())
	}

	return pass, err
}
开发者ID:carriercomm,项目名称:sky-1,代码行数:9,代码来源:ssh.go


示例16: push

func push(c *config.Config, q *registry.Queue) error {
	scriptsPath := utils.PackagePath(selfPkg)
	host := c.GetRequired("push")

	// FTP User & password
	user := q.NextTask()
	if user == "" {
		return fmt.Errorf("ftp user required as the first argument")
	}
	q.RemoveNextTask()

	password, err := gopass.GetPass(fmt.Sprintf("Enter \"%s\" password: ", user))
	if err != nil {
		return fmt.Errorf("cannot read password: %s", err)
	}
	if password == "" {
		return fmt.Errorf("ftp password is required")
	}

	// Hash local files
	log.Printf("Hashing local files... ")
	localHashes, err := hashLocalFiles()
	if err != nil {
		return fmt.Errorf("hash local files failed: %s", err)
	}
	log.Printf("Hashing local files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	// Hash remote files
	log.Printf("Hashing remote files... ")
	remoteHashes, err := retrieveRemoteHashes(scriptsPath, user, password, host)
	if err != nil {
		return fmt.Errorf("retrieve remote hashes failed: %s", err)
	}
	log.Printf("Hashing remote files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	if err := saveLocalHashes(localHashes); err != nil {
		return fmt.Errorf("save local hashes failed: %s", err)
	}

	// Prepare FTP commands
	log.Printf("Preparing FTP commands... ")
	if err := prepareFTPCommands(localHashes, remoteHashes); err != nil {
		return fmt.Errorf("prepare FTP commands failed: %s", err)
	}
	log.Printf("Preparing FTP commands... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	// Upload files
	log.Printf("Uploading files... ")
	if err := uploadFiles(scriptsPath, user, password, host); err != nil {
		return fmt.Errorf("uploading files failed: %s", err)
	}
	log.Printf("Uploading files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	return nil
}
开发者ID:ernestoalejo,项目名称:cb,代码行数:55,代码来源:push.go


示例17: MasterKeys

func MasterKeys() (masterKey []byte, masterPass string, err error) {
	masterPass, err = gopass.GetPass("Gimme MasterPassword: ")
	if err != nil {
		return masterKey, masterPass, fmt.Errorf("Error in Password input:", err)
	}
	masterKey, err = PaddingKey(masterPass)
	if err != nil {
		return masterKey, masterPass, fmt.Errorf("Error in Password input:", err)
	}
	return masterKey, masterPass, nil
}
开发者ID:devsmt,项目名称:gpws,代码行数:11,代码来源:gpws.go


示例18: getAuthInfo

// getAuthInfo get smtp authentication username and password
// from command line using gopass
func getAuthInfo() (string, string) {
	username := oneLiner("Enter username: ")

	password, passerr := gopass.GetPass("Enter password: ")
	if passerr != nil {
		fmt.Fprintf(os.Stderr, "get password error\n")
		panic(passerr)
	}

	return username, password
}
开发者ID:styxyang,项目名称:codelib,代码行数:13,代码来源:mailthem.go


示例19: main

func main() {
	usr, _ := user.Current()
	file = filepath.Join(usr.HomeDir, PASSWORD_DB)

	var operation, name, pass_ string
	var length int
	var pass []byte

	flag.StringVar(&operation, "o", "read", "operations: read / add / listkeys")
	flag.StringVar(&name, "n", "name", "key name")
	flag.IntVar(&length, "l", 16, "key length")
	flag.StringVar(&pass_, "p", "", "password to add")
	flag.Parse()

	if pass_ == "" {
		pass = randBytes(length)

	} else {
		pass = []byte(pass_)
	}

	key_, err := gopass.GetPass("Session Key ")
	if err != nil {
		panic(err)
	}
	key = []byte(key_)

	err = readdb()
	if err != nil {
		panic(err)
	}

	if operation == READ {
		err := read(name)
		if err != nil {
			panic(err)
		}
	}
	if operation == ADD {
		err := add(name, pass)
		if err != nil {
			panic(err)
		}

		err = savedb()
		if err != nil {
			panic(err)
		}
	}
	if operation == LISTKEYS {
		listkeys()
	}
}
开发者ID:jostillmanns,项目名称:passdb,代码行数:53,代码来源:passdb.go


示例20: main

func main() {
	if len(os.Args) < 2 {
		printUsage()
		return
	}

	if parseFlags() {
		return
	}

	master_key, err := gopass.GetPass(
		"Enter master key (recommended shorter than 16 bytes): ")
	if err != nil {
		panic(err)
	}

	c := cblib.Init(master_key)
	command := os.Args[1]
	website := []byte(os.Args[2])

	switch command {
	case "get":
		if bytes.Equal(website, []byte("all")) {
			c.PrintPlain()
			return
		}
		if pwd, err := c.Get(website); err == nil {
			fmt.Println(string(pwd))
			cblib.CopyToClipBoard(string(pwd))
		} else {
			panic(err)
		}
	case "new":
		var y_or_n string
		if pwd, err := c.Get(website); err == nil {
			fmt.Println(pwd)
			fmt.Println("Password already exists for", string(website))
		} else {
			new_code := cblib.NewPasscodeHard(15)
			fmt.Println(
				"The password for", string(website),
				"is", string(new_code),
				"\nAccept? (y/N):")
			_, _ = fmt.Scanf("%s", &y_or_n)
			if y_or_n != "N" || y_or_n != "n" {
				// when we add, it's encrypted
				c.Add(website, new_code)
				c.Save()
				cblib.CopyToClipBoard(string(new_code))
			}
		}
	}
}
开发者ID:nebgnahz,项目名称:Codebook,代码行数:53,代码来源:main.go



注:本文中的code/google/com/p/gopass.GetPass函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang draw.Display类代码示例发布时间:2022-05-24
下一篇:
Golang pcap.Handle类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap