Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func LoginPost(db *bolt.DB) iris.HandlerFunc {
- return func (c *iris.Context) {
- err := db.View(func (tx *bolt.Tx) error {
- b := tx.Bucket([]byte("user"))
- if b == nil {
- return fmt.Errorf("Bucket %s not found!", "user")
- }
- pass := b.Get(c.FormValue("name")) // returns []byte or nil
- if pass == nil {
- c.Session().Set("notice", "Invalid username or password")
- return fmt.Errorf("Invalid username: %q not found!", c.FormValue("name"))
- }
- // hash the passed in password and compare
- err := scrypt.CompareHashAndPassword(pass, []byte(c.FormValue("password")))
- if err != nil {
- c.SetFlash("notice","Invalid username or password")
- c.Session().Set("notice", "Invalid username or password")
- return fmt.Errorf("Invalid password for user %q", c.FormValue("name"))
- }
- // if we got this far - the password matches!
- iris.Logger.Println("Logged in")
- c.Session().Set("loggedIn", true)
- return nil
- })
- if err != nil {
- iris.Logger.Println(err.Error())
- c.Redirect("/admin/login", iris.StatusSeeOther)
- return
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement