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


Golang gopass.GetPass函数代码示例

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


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


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