This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type LoginForm struct { | |
utils.Flash | |
Username string | |
Password string | |
} | |
func (form *LoginForm) Validate() bool { | |
form.Errors = make(map[string]string) | |
if strings.TrimSpace(form.Password) == "" { | |
form.Errors["Password"] = "Password must not be blank" | |
} | |
if strings.TrimSpace(form.Username) == "" { | |
form.Errors["Username"] = "Username must not be blank" | |
} | |
else { | |
user, err := models.UserByName(form.Username) | |
if err != nil { | |
form.Errors["Username"] = "Username does not exist" | |
} else { | |
if err := bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(form.Password)); err != nil { | |
form.Errors["Password"] = "Password is incorrect" | |
} | |
} | |
} | |
return len(form.Errors) == 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment