func Auth(args martini.Params, r render.Render) { password := args["password"] hash, salt, err := auth.EncryptPassword(password) if err != nil { fmt.Println(err) } fmt.Printf("pass: %s\nhash: %s\nsalt: %s\n", password, hash, salt) fmt.Println("match: ", auth.MatchPassword(password, hash, salt)) }
func SetupAdminPost(sa forms.SetupAdmin, args martini.Params, session sessions.Session, r render.Render, res http.ResponseWriter, dbh *db.Dbh) { errs := Validate(&sa) if len(errs) > 0 { fmt.Printf("%+v\n", errs) } v := session.Get("setup") if v != "true" { http.Error(res, "Unauthorized", http.StatusUnauthorized) return } user := dbh.GetUserByEmail(sa.Email) if user.Id > 0 { fmt.Println("user already exists") session.Set("uid", user.Id) } if user.Id == 0 { fmt.Println("id: 0") hash, salt, err := auth.EncryptPassword(sa.Password) if err != nil { fmt.Println("hash err: ", err) } newuser := models.User{Name: sa.Name, Email: sa.Email, Password: hash, Salt: salt, Timestamp: time.Now().Unix()} dbh.InsertUser(newuser) session.Set("uid", newuser.Id) } uid := session.Get("uid") fmt.Println("uid: ", uid) genform := utils.GenerateForm(&sa, "/setup", "POST", errs) r.HTML(200, "setup", genform) }