password

package
v0.0.0-...-d57715f Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 密码生成类型
	CreatePWDWithNum     = "num"
	CreatePWDWithChar    = "char"
	CreatePWDWithMix     = "mix"
	CreatePWDWithAdvance = "advance"
)

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 DefaultEncryptor = Encryptor{
	// contains filtered or unexported fields
}
View Source
var ErrMD5PasswordInvalid = errors.New(`invalid password attributes. must provide "username" and "password"`)

ErrMD5PasswordInvalid is returned when the password attributes are invalid

Functions

func CreatePasswd

func CreatePasswd(length int, kind string) string

Types

type Encryptor

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

func NewEncryptor

func NewEncryptor(opts ...OptionFunc) *Encryptor

func (*Encryptor) Decrypt

func (e *Encryptor) Decrypt(ciphertext string) (string, error)

对密文进行多重解密

func (*Encryptor) DecryptSymmetric

func (e *Encryptor) DecryptSymmetric(ciphertext string) (string, error)

对密文进行对称解密

func (*Encryptor) Encrypt

func (e *Encryptor) Encrypt(plaintext string) (string, error)

对明文进行多重加密

func (*Encryptor) EncryptSymmetric

func (e *Encryptor) EncryptSymmetric(plaintext string) (string, error)

对明文进行对称加密

func (*Encryptor) ReplaceCharacters

func (e *Encryptor) ReplaceCharacters(plaintext string) string

对明文进行字符替换

func (*Encryptor) RestoreCharacters

func (e *Encryptor) RestoreCharacters(ciphertext string) string

对密文进行字符替换

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 OptionFunc

type OptionFunc func(o *Encryptor)

Option is an application option.

func Algorithm

func Algorithm(algorithm string) OptionFunc

func Iv

func Iv(iv string) OptionFunc

func Key

func Key(key string) OptionFunc

func ReplaceTable

func ReplaceTable(replaceTable string) OptionFunc

func ReplaceWith

func ReplaceWith(replaceWith string) OptionFunc

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