mc-client-updater-server/pkg/password/password.go

30 lines
525 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}