libgocredentials

package
Version: v0.0.0-...-6244057 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2018 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DEBUG	=  true
	DEBUG = false

	DEFAULT_SALT_LENGTH = 12
	BCRYPT_DEFAULT_COST = 10

	TRANSACTION_READ_UNCOMMITTED = "READ UNCOMMITTED"
	TRANSACTION_READ_COMMITTED   = "READ COMMITTED"
	TRANSACTION_REPEATABLE_READ  = "REPEATABLE READ"
	TRANSACTION_SERIALIZE        = "SERIALIZE"
)

Variables

View Source
var EOFError = io.EOF
View Source
var EmptyError = errors.New("empty argument!")
View Source
var FileNotExistsError = errors.New("File doesn't exists!")
View Source
var InvalidHashFormatError = errors.New("Invalid Hash Format!")
View Source
var InvalidUnixFormatError = errors.New("Invalid Unix password Format!")
View Source
var PasswordEmptyError = errors.New("Password is empty!")
View Source
var PlainPasswordNotAvailableError = errors.New("Plain Password wasn't saved!")
View Source
var TransactionAbortedError = errors.New("Transaction aborted!")
View Source
var UnexpectedFileFormatError = errors.New("Unexpected file format!")
View Source
var UnknownHashError = errors.New("Hash unknown!")
View Source
var UserDoesntExistError = errors.New("User does not exist!")
View Source
var UserExistsError = errors.New("User exists!")

Functions

func CCrypt

func CCrypt(key, salt string) string

wrapper around crypt_r see man crypt(3) for help

func IsTransactionIsolationLevel

func IsTransactionIsolationLevel(level string) bool

Types

type AuthenticationInterface

type AuthenticationInterface interface {
	// authenticate against plain password
	IsAuthenticated(user, password string) bool
}

type CredentialsInterface

type CredentialsInterface interface {
	AuthenticationInterface

	// Get a user by string
	Get(user string) (bool, UserInterface)

	// create a new user, but do not commit that user yet
	New(user, password string) (UserInterface, error)

	// add a new user
	// see New()
	Add(user UserInterface) error

	// modify existing user
	// get the user via Get() and change that user
	Modify(user UserInterface) error

	// remove a user
	// take the user from Get()
	Remove(user UserInterface) error

	// read next user
	// always call Reset() before
	// always call Reset() after finished
	Next() (UserInterface, error)

	// must be called when finished with Next()
	Reset()

	// close it
	Close() error
}

type DefaultSalter

type DefaultSalter struct {
	// contains filtered or unexported fields
}

func NewDefaultSalter

func NewDefaultSalter() *DefaultSalter

func (*DefaultSalter) GetSalt

func (salt *DefaultSalter) GetSalt() string

func (*DefaultSalter) NewSalt

func (salt *DefaultSalter) NewSalt() (random string, e error)

func (*DefaultSalter) SetSalt

func (salt *DefaultSalter) SetSalt(to string)

func (*DefaultSalter) SetSaltLength

func (salt *DefaultSalter) SetSaltLength(to uint8)

type ParserInterface

type ParserInterface interface {
	// contains filtered or unexported methods
}

type Passworder

type Passworder struct {
	// contains filtered or unexported fields
}

default Passworder uses Bcrypt, cant do nothing else

func NewPassworder

func NewPassworder() *Passworder

func NewPassworderParse

func NewPassworderParse(from string) (*Passworder, error)

func NewPassworderParsed

func NewPassworderParsed(hash, hashType, salt string) *Passworder

func (*Passworder) ChangePassword

func (passworder *Passworder) ChangePassword(plain string) (e error)

func (*Passworder) GetCost

func (passworder *Passworder) GetCost() int

func (*Passworder) GetHashType

func (passworder *Passworder) GetHashType() string

func (*Passworder) GetPasswordHash

func (passworder *Passworder) GetPasswordHash() string

func (*Passworder) GetSalt

func (passworder *Passworder) GetSalt() string

func (*Passworder) GetSalter

func (passworder *Passworder) GetSalter() SalterInterface

func (*Passworder) HasChanged

func (passworder *Passworder) HasChanged() bool

func (*Passworder) SetCost

func (passworder *Passworder) SetCost(to int)

func (*Passworder) SetSalter

func (passworder *Passworder) SetSalter(to SalterInterface)

func (*Passworder) TestPassword

func (passworder *Passworder) TestPassword(plain string) bool

type PassworderInterface

type PassworderInterface interface {
	// test current password hash against plain string
	TestPassword(plain string) bool

	// change password
	// remeber to use salt!
	ChangePassword(to string) error

	// has this passworder changed
	HasChanged() bool

	// get current password hash
	GetPasswordHash() string

	// get current salt
	GetSalt() string

	// get hash type
	GetHashType() string
	// contains filtered or unexported methods
}

type SalterInterface

type SalterInterface interface {
	// if to == 0, use DEFAULT_SALT_LENGTH
	SetSaltLength(to uint8)

	// generate a new salt
	NewSalt() (string, error)

	// get current salt
	GetSalt() string

	// set a salt
	// used for password checking
	// not for you to fiddle out your own salt!
	SetSalt(to string)
}

type Sql

type Sql struct {
	// contains filtered or unexported fields
}

func NewSql

func NewSql(sqlConfig *SqlConfig) *Sql

func (*Sql) Add

func (sql *Sql) Add(user UserInterface) (e error)

func (*Sql) Begin

func (sql *Sql) Begin()

func (*Sql) Close

func (sql *Sql) Close() error

func (*Sql) Commit

func (sql *Sql) Commit()

func (*Sql) Get

func (sql *Sql) Get(name string) (bool, UserInterface)

func (*Sql) IsAuthenticated

func (sql *Sql) IsAuthenticated(name, password string) bool

func (*Sql) Modify

func (sql *Sql) Modify(user UserInterface) (e error)

func (*Sql) New

func (sql *Sql) New(user, password string) (UserInterface, error)

func (*Sql) Next

func (sql *Sql) Next() (UserInterface, error)

func (*Sql) Remove

func (sql *Sql) Remove(user UserInterface) (e error)

func (*Sql) Reset

func (sql *Sql) Reset()

func (*Sql) Rollback

func (sql *Sql) Rollback()

func (*Sql) SetTransactionIsolationLevel

func (sql *Sql) SetTransactionIsolationLevel(to string)

type SqlConfig

type SqlConfig struct {
	Base, Table string

	Database *sqldb.DB
	// contains filtered or unexported fields
}

type TransactionInterface

type TransactionInterface interface {
	Begin()
	SetTransactionIsolationLevel(to string)
	Commit()
	Rollback()
}

type Unix

type Unix struct {
	// contains filtered or unexported fields
}

reads and modifys /etc/shadow format rewrites entire file on Add(), Modify() and Remove() calls writes are done to a temp file which is then moved

func NewUnix

func NewUnix(newFilename string) *Unix

func (*Unix) Add

func (unix *Unix) Add(user UserInterface) (e error)

writes to a temp file and then trys to move that temp file

func (*Unix) Close

func (unix *Unix) Close() (e error)

func (*Unix) Get

func (unix *Unix) Get(name string) (found bool, user UserInterface)

func (*Unix) IsAuthenticated

func (unix *Unix) IsAuthenticated(name, password string) bool

func (*Unix) Modify

func (unix *Unix) Modify(user UserInterface) (e error)

func (*Unix) New

func (unix *Unix) New(user, password string) (UserInterface, error)

func (*Unix) Next

func (unix *Unix) Next() (user UserInterface, e error)

func (*Unix) Remove

func (unix *Unix) Remove(user UserInterface) (e error)

func (*Unix) Reset

func (unix *Unix) Reset()

type UnixPassworder

type UnixPassworder struct {
	Passworder
	// contains filtered or unexported fields
}

reads and creates passwords used in /etc/shadow only supports md5, sha256 and sha512 while parsing requires salt

func NewUnixPassworder

func NewUnixPassworder() *UnixPassworder

func NewUnixPassworderFromString

func NewUnixPassworderFromString(from string) *UnixPassworder

func NewUnixPassworderParse

func NewUnixPassworderParse(from string) (*UnixPassworder, error)

func (*UnixPassworder) ChangePassword

func (passworder *UnixPassworder) ChangePassword(to string) (e error)

func (*UnixPassworder) TestPassword

func (passworder *UnixPassworder) TestPassword(plain string) bool

type UnixUser

type UnixUser struct {
	User
	// contains filtered or unexported fields
}

func CreateUnixUser

func CreateUnixUser(username, password string) (user *UnixUser, e error)

func NewUnixUser

func NewUnixUser(username string) (user *UnixUser)

type User

type User struct {
	// contains filtered or unexported fields
}

func CreateUser

func CreateUser(to, password string) (*User, error)

func NewUser

func NewUser(to string) *User

func (*User) ChangePassword

func (user *User) ChangePassword(to string) error

func (*User) GetName

func (user *User) GetName() string

func (*User) GetPasswordHash

func (user *User) GetPasswordHash() string

func (*User) GetPassworder

func (user *User) GetPassworder() PassworderInterface

func (*User) HasChanged

func (user *User) HasChanged() bool

type UserInterface

type UserInterface interface {
	// get user name
	GetName() string

	// get passworder
	GetPassworder() PassworderInterface

	// change password
	// set hasChanged
	ChangePassword(to string) error

	// get current password hash
	// shortcut for user.GetPassworder().GetPasswordHash()
	GetPasswordHash() string

	// has this user been changed
	HasChanged() bool
	// contains filtered or unexported methods
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL