keymgr

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: MIT Imports: 8 Imported by: 0

README

keymgr (Credentials Manager)

Golang / Windows Credential Manager Wrapper

A small library that interacts with Go and Windows Credential Manager.

It incorporates Windows Credential GUI. It also uses and is integrated with the status The Credentials will be stored with the Following format.

- Windows Credential Manager - Generic Credentials
- format:
- *['program name']~['Server name or Address']*
Example

This is a dummy connect and returns an int value.

package main
import (
	"fmt"
	"gopkg.in/ro-ag/keymgr.v1"
)

// This example prepares the keymgr.Cred type
// Login function needs a CallBack type function with interface return
// The Flow Actions in Login function ( this example ):
//  1.- Check if Credentials with name *[keymgr]~[test]* exits
//      1.1.- If exists go to step 5
//  2.- Run a GUI to prompt user and password
//  3.- Store Credentials in Windows Credential Manager
//  4.- Load Credentials ( check if works )
//  5.- Run connect function
//      5.1 - If status is not 0 remove credentials
//      5.2 - Go to Step 2
//      5.3 - if Attempts is >= Limit return nil
//  6.- Return connect interface

func main() {
	Parameters := keymgr.Cred{
		Program: "keymgr",   // Program Name Identifier
		Target:  "Test",       // Target, usually a site or server
		Limit:   3,            // Number of Attempts before return nil
		Debug:   true,         // Internal Log messages
	}
	out := Parameters.Login(connect).(int) // CallBack function
	fmt.Println(out)
}


// This function Simulate any type of connection passing keymgr.CallArgs structure
//  .User : User From Windows Credential Manager
//  .Pass : Password
//  .Target  : Normally Site or Server ( this comes from keymgr.Cred { .Target } type )
//  .Attempt : Current number of attempts to run connect function
// The function will pass when status is set to 0

func connect( Credentials keymgr.CallArgs, status *int )interface{}{
	if Credentials.User == "pepe" && Credentials.Pass == "pepepass" {
		fmt.Println("User  : ", Credentials.User)
		fmt.Println("Pass  : ", Credentials.Pass)
		*status = 0
	} else {
        fmt.Println("  Target: ", Credentials.Target)
		fmt.Println("  User  : ", Credentials.User)
		fmt.Println("  Pass  : ", Credentials.Pass)
		fmt.Println("  Attempt : ", Credentials.Attempts)
		*status = 1
	}
	// Return int
	return *status
}

Documentation

Overview

Package keymgr adds a simple wrapper to Windows Credential Manager for the Go language. This package requires MinGW-64

Source code and other details for the project are available at GitHub:

https://github.com/ro-ag/keymgr

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallArgs

type CallArgs struct {
	Target   string // Target normally is a Site or Server ( already passed in Cred Structure )
	User     string // User from Credential Manager
	Pass     string // PassWord from Credential Manager
	Attempts int    // Current number of attempts
}

CallArgs : Needed for CallBack function, it contains the User, Password, Target ( usually a server or site ) Attempts is the current time the credentials are prompted

type Cred

type Cred struct {
	Program string `validate:"nonzero"` // Program identifier
	Target  string `validate:"nonzero"` // Target normally is a Site or Server
	Limit   int    `validate:"min=1"`   // Limit of login intents before fail
	Debug   bool   // Print keymgr log information
}

Cred : Initial Structure

func (*Cred) Login

func (P *Cred) Login(CallBack func(CallArgs, *int) interface{}) (OutLogin interface{})

Login : This function needs a CallBack function with interface return The Flow Actions in Login function:

1.- Check if Credentials with name "*[Program]~[Target]*" exits
    1.1.- If exists go to step 5
2.- Run a GUI to prompt user and password
3.- Store Credentials in Windows Credential Manager
4.- Load Credentials ( check if works )
5.- Run "CallBack" function
    5.1 - If status is not 0 remove credentials
    5.2 - Go to Step 2
    5.3 - if Attempts is >= Limit return nil
6.- Return "CallBack" interface

Jump to

Keyboard shortcuts

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