feat: password.

This commit is contained in:
Bobo
2025-06-14 23:28:15 +08:00
parent 3ca4745bac
commit be5aa063df
19 changed files with 1109 additions and 0 deletions

29
password/interface.go Normal file
View File

@@ -0,0 +1,29 @@
package password
import (
"errors"
"strings"
)
// Crypto 密码加解密接口
type Crypto interface {
// Encrypt 加密密码,返回加密后的字符串(包含算法标识和盐值)
Encrypt(plainPassword string) (encrypted string, err error)
// Verify 验证密码是否匹配
Verify(plainPassword, encrypted string) (bool, error)
}
func CreateCrypto(algorithm string) (Crypto, error) {
algorithm = strings.ToLower(algorithm)
switch algorithm {
case "bcrypt":
return NewBCryptCrypto(), nil
case "pbkdf2":
return NewPBKDF2Crypto(), nil
case "argon2":
return NewArgon2Crypto(), nil
default:
return nil, errors.New("不支持的加密算法")
}
}