Created
December 24, 2016 08:23
-
-
Save ColemanGariety/88cfec5a7ce7b2e0b8e2c33ae46d191b to your computer and use it in GitHub Desktop.
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