Beispiel #1
0
func initCmd(cmd *cobra.Command, args []string) error {
	db = gokeepasslib.NewDatabase()

	if _, err := os.Stat(filePath); err == nil {
		return fmt.Errorf("File at '%s' already exists", filePath)
	}

	var (
		password string
		err      error
	)

	if usePassword {
		password, err = readPasswordWithConfirmation()
		if err != nil {
			return err
		}
	}

	credentials, err := pickCredentialMode(password)
	if err != nil {
		return fmt.Errorf("Failed to setup credentials: '%s'", err)
	}

	db.Credentials = credentials
	changed = true

	return nil
}
Beispiel #2
0
func main() {
	file, _ := os.Open("./example.kdbx")

	db := gokeepasslib.NewDatabase()
	db.Credentials = gokeepasslib.NewPasswordCredentials("abcdefg12345678")
	_ = gokeepasslib.NewDecoder(file).Decode(db)

	db.UnlockProtectedEntries()

	entry := db.Content.Root.Groups[0].Groups[0].Entries[0]
	fmt.Println(entry.GetTitle())
	fmt.Println(entry.GetPassword())
}