Documentation
¶
Index ¶
- Variables
- func CheckPassword(password, hash string) error
- func CompareHashAndPassword(encodedHash string, password []byte) error
- func GenerateFromPassword(password []byte, params *Params) (string, error)
- func GetPasswordStrengthDescription(strength PasswordStrength) string
- func HashPassword(password string) (string, error)
- func NeedsRehash(encodedHash string, params *Params) (bool, error)
- type Params
- type PasswordStrength
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInvalidHash 表示哈希格式无效 ErrInvalidHash = errors.New("提供的密码哈希格式无效") // ErrIncompatibleVersion 表示哈希使用了不支持的版本 ErrIncompatibleVersion = errors.New("不兼容的哈希版本") // ErrMismatchedHashAndPassword 表示密码与存储的哈希不匹配 ErrMismatchedHashAndPassword = errors.New("密码与哈希不匹配") )
错误定义
Functions ¶
func CheckPassword ¶
CheckPassword 是对CompareHashAndPassword的简单封装
func CompareHashAndPassword ¶
CompareHashAndPassword 比较密码与其哈希值 成功时返回nil,失败时返回错误
func GenerateFromPassword ¶
GenerateFromPassword 使用Argon2id算法从密码生成加密哈希 返回的哈希格式为:$argon2id$v=19$m=65536,t=3,p=4$<salt>$<hash> 注意:该函数将创建一个新的随机盐用于每次哈希生成
func GetPasswordStrengthDescription ¶
func GetPasswordStrengthDescription(strength PasswordStrength) string
GetPasswordStrengthDescription 获取密码强度描述
func HashPassword ¶
HashPassword 是对GenerateFromPassword的简单封装,使用默认参数
Types ¶
type Params ¶
type Params struct {
// Memory 内存使用量(KB)
Memory uint32
// Iterations 迭代次数
Iterations uint32
// Parallelism 并行度
Parallelism uint8
// SaltLength 盐长度(字节)
SaltLength uint32
// KeyLength 输出密钥长度(字节)
KeyLength uint32
}
Params 结构定义了用于Argon2id哈希算法的参数
func DefaultParams ¶
func DefaultParams() *Params
DefaultParams 返回默认的Argon2id参数 这些默认参数基于OWASP和Argon2id的建议
type PasswordStrength ¶
type PasswordStrength int
PasswordStrength 表示密码强度级别
const ( // VeryWeak 表示非常弱的密码 VeryWeak PasswordStrength = iota // Weak 表示弱密码 Weak // Medium 表示中等强度密码 Medium // Strong 表示强密码 Strong // VeryStrong 表示非常强的密码 VeryStrong )
func CheckPasswordStrength ¶
func CheckPasswordStrength(password string) PasswordStrength
CheckPasswordStrength 检查密码强度
Click to show internal directories.
Click to hide internal directories.