50 lines
1022 B
Go
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
|
|
}
|