本文整理匯總了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!")
}
示例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
}
示例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
}
示例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
}
示例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: ")
}
示例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
}
}
示例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
}
示例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
}
示例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)
}
}
示例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)
}
示例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
}
示例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)
}
}
示例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)
}
}
示例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)
}
示例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
}