serverctl/services/entry/pkg/application/users/user.go
2022-02-14 20:03:53 +01:00

50 lines
1022 B
Go

package users
import "errors"
type PasswordHasher interface {
HashPassword(password string) string
}
type CreateUser struct {
Email string
PasswordHash string
}
func NewCreateUser(email string, password string, hasher PasswordHasher) (*CreateUser, error) {
if email == "" {
return nil, errors.New("Email cannot be empty for user")
}
if password == "" || len(password) < 8 {
return nil, errors.New("password is doesn't fit requirements")
}
return &CreateUser{
Email: email,
PasswordHash: hasher.HashPassword(password),
}, nil
}
type bCryptPasswordHasher struct {
}
func NewBCryptPasswordHasher() PasswordHasher {
return &bCryptPasswordHasher{}
}
func (b bCryptPasswordHasher) HashPassword(password string) string {
//TODO implement me
panic("implement me")
}
type plainTextPasswordHasher struct {
}
func NewPlainTextPasswordHasher() PasswordHasher {
return &plainTextPasswordHasher{}
}
func (p plainTextPasswordHasher) HashPassword(password string) string {
return password
}