cryptox

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GeneratePassword

func GeneratePassword(config PasswordConfig) (string, error)

GeneratePassword 生成密码

func GenerateSimplePassword

func GenerateSimplePassword(length int) (string, error)

GenerateSimplePassword 生成简单密码 (仅包含字母和数字)

func GenerateStrongPassword

func GenerateStrongPassword(length int) (string, error)

GenerateStrongPassword 生成强密码 (包含所有字符类型)

func InitPasswordConfig

func InitPasswordConfig(config *PasswordConf)

InitPasswordConfig 初始化密码配置

func VerifyPassword

func VerifyPassword(password string, ph *PasswordHash) bool

VerifyPassword 验证密码

Types

type PasswordConf

type PasswordConf struct {
	Time    uint32
	Memory  uint32
	Threads uint8
	KeyLen  uint32
}

PasswordConf 密码哈希配置

func DefaultConfig

func DefaultConfig() *PasswordConf

DefaultConfig 返回推荐的配置参数

func GetPasswordConfig

func GetPasswordConfig() *PasswordConf

GetPasswordConfig 获取密码配置

type PasswordConfig

type PasswordConfig struct {
	Length       int  // 密码长度
	Numbers      bool // 是否包含数字
	LowerLetters bool // 是否包含小写字母
	UpperLetters bool // 是否包含大写字母
	SpecialChars bool // 是否包含特殊字符
	MinNumbers   int  // 最少数字数量
	MinLowerCase int  // 最少小写字母数量
	MinUpperCase int  // 最少大写字母数量
	MinSpecial   int  // 最少特殊字符数量
}

PasswordConfig 密码生成配置

type PasswordHash

type PasswordHash struct {
	Hash []byte
	Salt []byte
}

PasswordHash 密码哈希结构

func FromString

func FromString(s string) (*PasswordHash, error)

FromString 从字符串还原哈希信息

func HashPassword

func HashPassword(password string) (*PasswordHash, error)

HashPassword 使用单例配置进行哈希

func (*PasswordHash) ToString

func (ph *PasswordHash) ToString() string

ToString 将哈希信息转为字符串存储

Jump to

Keyboard shortcuts

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