Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. func LoginPost(db *bolt.DB) iris.HandlerFunc {
  2. return func (c *iris.Context) {
  3. err := db.View(func (tx *bolt.Tx) error {
  4. b := tx.Bucket([]byte("user"))
  5. if b == nil {
  6. return fmt.Errorf("Bucket %s not found!", "user")
  7. }
  8. pass := b.Get(c.FormValue("name")) // returns []byte or nil
  9. if pass == nil {
  10. c.Session().Set("notice", "Invalid username or password")
  11. return fmt.Errorf("Invalid username: %q not found!", c.FormValue("name"))
  12. }
  13. // hash the passed in password and compare
  14. err := scrypt.CompareHashAndPassword(pass, []byte(c.FormValue("password")))
  15. if err != nil {
  16. c.SetFlash("notice","Invalid username or password")
  17. c.Session().Set("notice", "Invalid username or password")
  18. return fmt.Errorf("Invalid password for user %q", c.FormValue("name"))
  19. }
  20. // if we got this far - the password matches!
  21. iris.Logger.Println("Logged in")
  22. c.Session().Set("loggedIn", true)
  23. return nil
  24. })
  25. if err != nil {
  26. iris.Logger.Println(err.Error())
  27. c.Redirect("/admin/login", iris.StatusSeeOther)
  28. return
  29. }
  30.  
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement