30 lines
525 B
Go
30 lines
525 B
Go
|
package password
|
|||
|
|
|||
|
import (
|
|||
|
"mc-client-updater-server/pkg/conf"
|
|||
|
"mc-client-updater-server/pkg/log"
|
|||
|
"sync"
|
|||
|
)
|
|||
|
|
|||
|
var (
|
|||
|
once sync.Once
|
|||
|
encoder Encoder
|
|||
|
)
|
|||
|
|
|||
|
func Password() Encoder {
|
|||
|
once.Do(func() {
|
|||
|
switch conf.Conf.Security.PasswordEncoder {
|
|||
|
case "argon2id":
|
|||
|
encoder = &Argon2id{}
|
|||
|
default:
|
|||
|
log.Logger.Fatal("非法的PasswordEncoder类型:", conf.Conf.Security.PasswordEncoder)
|
|||
|
}
|
|||
|
})
|
|||
|
return encoder
|
|||
|
}
|
|||
|
|
|||
|
type Encoder interface {
|
|||
|
Create(string) (string, error)
|
|||
|
Verify(password, hash string) (bool, error)
|
|||
|
}
|