wincred

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2016 License: MIT Imports: 6 Imported by: 79

README

wincred

Go wrapper around the Windows Credential Manager API functions.

Build status GoDoc

Installation

go get github.com/danieljoos/wincred

Usage

See the following examples:

Create and store a new generic credential object
package main

import (
    "fmt"
    "github.com/danieljoos/wincred"
)

func main() {
    cred := wincred.NewGenericCredential("myGoApplication")
    cred.CredentialBlob = []byte("my secret")
    err := cred.Write()
    
    if err != nil {
        fmt.Println(err)
    }
} 
Retrieve a credential object
package main

import (
    "fmt"
    "github.com/danieljoos/wincred"
)

func main() {
    cred, err := wincred.GetGenericCredential("myGoApplication")
    if err == nil {
        fmt.Println(string(cred.CredentialBlob))
    }
} 
Remove a credential object
package main

import (
    "fmt"
    "github.com/danieljoos/wincred"
)

func main() {
    cred, err := wincred.GetGenericCredential("myGoApplication")
    if err != nil {
        fmt.Println(err)
        return
    }
    cred.Delete()
} 
List all available credentials
package main

import (
    "fmt"
    "github.com/danieljoos/wincred"
)

func main() {
    creds, err := wincred.List()
    if err != nil {
        fmt.Println(err)
        return
    }
    for i := range(creds) {
        fmt.Println(creds[i].TargetName)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Credential

type Credential struct {
	TargetName     string
	Comment        string
	LastWritten    time.Time
	CredentialBlob []byte
	Attributes     []CredentialAttribute
	TargetAlias    string
	UserName       string
	Persist        CredentialPersistence
}

func List

func List() ([]*Credential, error)

List the contents of the Credentials store

type CredentialAttribute

type CredentialAttribute struct {
	Keyword string
	Value   []byte
}

type CredentialPersistence

type CredentialPersistence uint32
const (
	PersistSession      CredentialPersistence = 0x1
	PersistLocalMachine CredentialPersistence = 0x2
	PersistEnterprise   CredentialPersistence = 0x3
)

type DomainPassword

type DomainPassword struct {
	Credential
}

func GetDomainPassword

func GetDomainPassword(targetName string) (*DomainPassword, error)

Get the domain password credential with the given target host name

func NewDomainPassword

func NewDomainPassword(targetName string) (result *DomainPassword)

Create a new domain password credential used for login to the given target host name

func (*DomainPassword) Delete

func (t *DomainPassword) Delete() (err error)

Delete the domain password credential from Windows credential manager

func (*DomainPassword) SetPassword

func (t *DomainPassword) SetPassword(pw string)

Set the CredentialBlob field of a domain password credential using an UTF16 encoded password string

func (*DomainPassword) Write

func (t *DomainPassword) Write() (err error)

Persist the domain password credential to Windows credential manager

type GenericCredential

type GenericCredential struct {
	Credential
}

func GetGenericCredential

func GetGenericCredential(targetName string) (*GenericCredential, error)

Get the generic credential with the given name from Windows credential manager

func NewGenericCredential

func NewGenericCredential(targetName string) (result *GenericCredential)

Create a new generic credential with the given name

func (*GenericCredential) Delete

func (t *GenericCredential) Delete() (err error)

Delete the credential from Windows credential manager

func (*GenericCredential) Write

func (t *GenericCredential) Write() (err error)

Persist the credential to Windows credential manager

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL