mirror of
https://github.com/xiaoqidun/idkey.git
synced 2024-12-22 13:41:07 +08:00
密码从string改为[]byte类型
This commit is contained in:
parent
5ebdc04340
commit
5dcac0a3fb
@ -5,7 +5,7 @@ go get -u github.com/xiaoqidun/idkey
|
||||
# 使用方法
|
||||
```go
|
||||
// 生成argon2id hash密码
|
||||
hash := idkey.Encode("admin")
|
||||
hash := idkey.Encode([]byte("admin"))
|
||||
// 进行argon2id hash验证
|
||||
verify := idkey.Verify("admin", hash)
|
||||
verify := idkey.Verify([]byte("admin"), hash)
|
||||
```
|
||||
|
8
idkey.go
8
idkey.go
@ -19,7 +19,7 @@ type Data struct {
|
||||
KeyLen uint32 // 密文长度
|
||||
}
|
||||
|
||||
func Encode(password string) string {
|
||||
func Encode(password []byte) string {
|
||||
salt := generateSalt(16)
|
||||
data := &Data{
|
||||
Hash: nil,
|
||||
@ -30,7 +30,7 @@ func Encode(password string) string {
|
||||
KeyLen: 32,
|
||||
}
|
||||
hash := argon2.IDKey(
|
||||
[]byte(password),
|
||||
password,
|
||||
data.Salt,
|
||||
data.Time,
|
||||
data.Memory,
|
||||
@ -92,13 +92,13 @@ func Decode(passwordHash string) (data *Data, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func Verify(password, passwordHash string) bool {
|
||||
func Verify(password []byte, passwordHash string) bool {
|
||||
data, err := Decode(passwordHash)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
hash := argon2.IDKey(
|
||||
[]byte(password),
|
||||
password,
|
||||
data.Salt,
|
||||
data.Time,
|
||||
data.Memory,
|
||||
|
Loading…
x
Reference in New Issue
Block a user