8
"xelbot.com/reprogl/container"
9
"xelbot.com/reprogl/models"
10
"xelbot.com/reprogl/models/repositories"
11
"xelbot.com/reprogl/security"
15
InfoLogMessage() string
18
type wrongCredentialsError struct {
22
func HandleLoginPassword(app *container.Application, username, password string) (*models.LoggedUser, error) {
23
if len(username) == 0 || len(password) == 0 {
24
return nil, wrongCredentialsError{info: "username or password is empty"}
27
if len(password) > 4096 {
28
return nil, wrongCredentialsError{info: "password too long"}
31
repo := repositories.UserRepository{DB: app.DB}
32
user, err := repo.GetLoggedUserByUsername(username)
34
if errors.Is(err, models.RecordNotFound) {
35
return nil, wrongCredentialsError{info: fmt.Sprintf("user \"%s\" not found", username)}
41
passwordHash := security.EncodePassword(password, user.Salt)
42
if subtle.ConstantTimeCompare([]byte(passwordHash), []byte(user.PasswordHash)) == 0 {
43
return nil, wrongCredentialsError{info: fmt.Sprintf("invalid password for \"%s\"", username)}
49
func (_ wrongCredentialsError) Error() string {
50
return "Недействительные логин/пароль"
53
func (w wrongCredentialsError) InfoLogMessage() string {