func (key *KeyStore) Set() (string, error) { stdin := os.Stdin os.Stdin, _ = os.Open("/dev/tty") for { pw, err := prompt.Password("Set the password in file: ") if err != nil { fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error()) break } if len(pw) > 32 { fmt.Fprintf(os.Stderr, "Error: %s\n", ErrPassordLenOver.Error()) continue } if err := ioutil.WriteFile(key.file, []byte(pw), 0600); err != nil { return "", err } os.Stdin = stdin return pw, nil } return "", ErrNotSetPassword }
func (key *KeyStore) Set() (string, error) { stdin := os.Stdin os.Stdin, _ = os.Open("/dev/tty") for { pw, err := prompt.Password("Set the password in keychain: ") if err != nil { fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error()) break } if len(pw) > 32 { fmt.Fprintf(os.Stderr, "Error: %s\n", ErrPassordLenOver.Error()) continue } keychain.Remove(key.name, "") if err := keychain.Add(key.name, "", pw); err != nil { fmt.Fprintf(os.Stderr, "Error: %s\n\n", err) continue } os.Stdin = stdin return pw, nil } return "", ErrNotSetPassword }
func ExamplePassword() ([]byte, error) { clear, err := prompt.Password("Password") if err != nil { return nil, err } return bcrypt.GenerateFromPassword([]byte(clear), bcrypt.DefaultCost) }
// NewConfiguration prompts the user for the gitub credentials and creates a // configuration with an access token func NewConfiguration() (*Configuration, error) { u, err := prompt.BasicDefault("Username: "******"USER")) if err != nil { return nil, err } pw, err := prompt.Password("Password: "******"POST", authURL, bytes.NewBufferString(authJSON)) if err != nil { return nil, err } req.SetBasicAuth(u, pw) client := new(http.Client) res, err := client.Do(req) if err != nil { return nil, err } body, err := ioutil.ReadAll(res.Body) res.Body.Close() if err != nil { return nil, err } if res.StatusCode > 400 { return nil, fmt.Errorf("could not get token, code: %d, body: %s", res.StatusCode, body) } r := new(authResponse) err = json.Unmarshal(body, &r) if err != nil { return nil, err } c := &Configuration{ Username: u, Private: true, Token: r.Token, } return c, nil }