I use postgresql and go and even the postman. I'm trying to check the login and password in the database. But the response from the server do not get
func checkUser(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
var rec User
err := json.NewDecoder(r.Body).Decode(&rec)
if err != nil || rec.Login == "" || rec.Password == "" {
w.WriteHeader(400)
return
}
result := db.QueryRow("select password from users where login ='&1'", rec.Login)
if err != nil {
w.WriteHeader(500)
return
}
var storedRecs User
err = result.Scan(storedRecs.Password)
if err != nil {
if err == sql.ErrNoRows {
w.WriteHeader(401)
return
}
w.WriteHeader(500) //PROBLEM HERE
return
}
if err = bcrypt.CompareHashAndPassword([]byte(storedRecs.Password), []byte(rec.Password)); err != nil {
w.WriteHeader(401)
}
w.Write([]byte(fmt.Sprintf("Well done")))
}
Comments
Post a Comment