Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrPasswordMismatch = errors.New("password hash does not match") ErrInvalidHashFormat = errors.New("invalid argon2id hash format") ErrIncompatibleVersion = errors.New("incompatible argon2 version") )
hasher errors
Functions ¶
func GenerateRandomString ¶
GenerateRandomString generates a cryptographically secure random string of the specified length.
Types ¶
type Argon2Hasher ¶
type Argon2Hasher struct {
// contains filtered or unexported fields
}
Argon2Hasher 是使用 Argon2id 算法的 Hasher 实现。
func NewArgon2Hasher ¶
func NewArgon2Hasher(memory uint32, time uint32, threads uint8, keyLen uint32, saltLen uint32) *Argon2Hasher
NewArgon2Hasher 创建一个带有推荐参数的新实例。 这些参数可以从配置中读取以增加灵活性。
type BcryptHasher ¶
type BcryptHasher struct {
// contains filtered or unexported fields
}
BcryptHasher 是使用Bcrypt算法的Hasher实现。
func NewBcryptHasher ¶
func NewBcryptHasher(cost int) *BcryptHasher
NewBcryptHasher 创建一个新的BcryptHasher实例。 它接收一个cost参数,提供了灵活性,同时在函数内部强制执行一个合理的最小成本值, 防止在配置时意外设置一个不安全的值。
type Hasher ¶
type Hasher interface {
// Hash 对给定的明文密码进行哈希处理。
// 返回哈希后的字节切片或错误。
Hash(ctx context.Context, password []byte) ([]byte, error)
// Compare 将明文密码与已有的哈希值进行比较。
// 如果匹配,则返回nil;否则返回错误。
Compare(ctx context.Context, hashedPassword []byte, password []byte) error
}
Hasher 定义了密码哈希和验证的接口。 这是一种策略模式的应用,将具体的哈希算法与业务逻辑解耦。
Click to show internal directories.
Click to hide internal directories.