Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
db.go

func Findaccount(myEmail, myPassword string) bool {
    collection := Connect.Database("webApp3").Collection("data")
    collection.FindOne(context.TODO(), bson.M{"email": myEmail}).Decode(&Account)
    err := bcrypt.CompareHashAndPassword([]byte(Account.Password), []byte(myPassword))
    return err == nil
}



handler.go

func about(res http.ResponseWriter, req *http.Request) {
    if req.Method != http.MethodPost {
	tmpl.ExecuteTemplate(res, "about.html", nil)
	    return
    }
    email := database.Account.Email
    password := database.Account.Password
    content := req.FormValue("content")
    match := database.Findaccount(email, password)
    tmpl.ExecuteTemplate(res, "about.html", nil)

    if match == true {
        database.Updatedata("about", content)
    } else {
	fmt.Fprintf(res, "<h1> Error </h1>")
    }
}


What I have tried:

In this code, I have an about function that is first verifying the email, and password from the database(MongoDB), and content from the about page form.

When I print all the above variables, they show me the correct data. But when I give the if-statement to check if the email and password are true then the boolean does not work. I don't know why?

How to solve this problem?
Posted
Updated 21-Jan-22 3:16am
Comments
Richard MacCutchan 3-Aug-21 3:50am    
"the boolean does not work."
What exactly does that mean? Do you get true, false or something else?
Richard Deeming 3-Aug-21 4:00am    
email := database.Account.Email
password := database.Account.Password

I don't know "go", but that doesn't look right to me. Shouldn't you be taking the username and password from the request instead?

1 solution

return (err == nil)


How about this?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900