password

package
v4.5.1-1+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSCRAMPasswordInvalid is returned when the password attributes are invalid
	ErrSCRAMPasswordInvalid = errors.New(`invalid password attributes. must provide "password"`)
	// ErrSCRAMSaltLengthInvalid is returned when the salt length is less than 1
	ErrSCRAMSaltLengthInvalid = errors.New(`salt length must be at least 1`)
)
View Source
var (
	// ErrMD5PasswordInvalid is returned when the password attributes are invalid
	ErrMD5PasswordInvalid = errors.New(`invalid password attributes. must provide "username" and "password"`)
)
View Source
var (
	// ErrPasswordType is returned when a password type does not exist
	ErrPasswordType = errors.New("password type does not exist")
)

Functions

This section is empty.

Types

type MD5Password

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

MD5Password implements the PostgresPassword interface for hashing passwords using the PostgreSQL MD5 method

func NewMD5Password

func NewMD5Password(username, password string) *MD5Password

NewMD5Password constructs a new MD5Password struct

func (*MD5Password) Build

func (m *MD5Password) Build() (string, error)

Build creates the MD5 password format for PostgreSQL which resembles "md5" + md5("password" + "username")

type PasswordType

type PasswordType int

PasswordType helps to specify the type of password method (e.g. md5) to use

const (
	// MD5 refers to the MD5Password method
	MD5 PasswordType = iota
	SCRAM
)

The following constants are used to aid in the select of the types of PostgreSQL password generators

type PostgresPassword

type PostgresPassword interface {
	// Build transforms any plaintext or other attributes that are provided by
	// the interface implementor and returns a password. If an error occurs in the
	// building process, it is returned.
	//
	// If the build does error, return an empty string
	Build() (string, error)
}

PostgresPassword is the interface that defines the methods required to build a password for PostgreSQL in a desired format (e.g. MD5)

func NewPostgresPassword

func NewPostgresPassword(passwordType PasswordType, username, password string) (PostgresPassword, error)

NewPostgresPassword accepts a type of password (e.g. md5) which is used to select the correct generation interface, as well as a username and password and returns the appropriate interface

An error is returned if the proper password generator cannot be found

type SCRAMPassword

type SCRAMPassword struct {
	// Iterations is the number of iterations to run the PBKDF2 algorithm when
	// generating the hashed salted password. This defaults to 4096, which is the
	// PostgreSQL default
	Iterations int
	// SaltLength is the length of the generated salt that is used as part of the
	// PBKDF2 algorithm
	SaltLength int
	// contains filtered or unexported fields
}

SCRAMPassword contains the building blocks to build a PostgreSQL SCRAM verifier. Implements the PostgresPassword interface

func NewSCRAMPassword

func NewSCRAMPassword(password string) *SCRAMPassword

NewSCRAMPassword constructs a new SCRAMPassword struct with sane defaults

func (*SCRAMPassword) Build

func (s *SCRAMPassword) Build() (string, error)

Build creates the SCRAM verifier, which follows the methods defined in the PostgreSQL source, i.e.

https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/common/scram-common.h

Jump to

Keyboard shortcuts

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