Skip to content

Instantly share code, notes, and snippets.

@JacksonGariety
Created December 24, 2016 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacksonGariety/88cfec5a7ce7b2e0b8e2c33ae46d191b to your computer and use it in GitHub Desktop.
Save JacksonGariety/88cfec5a7ce7b2e0b8e2c33ae46d191b to your computer and use it in GitHub Desktop.
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