Bcrypt password hashing in Golang (compatible with Node.js)?

后端 未结 3 1723
情深已故
情深已故 2020-12-12 14:22

I set up a site with Node.js+passport for user authentication.

Now I need to migrate to Golang, and need to do authentication with the user passwords saved in db. <

3条回答
  •  Happy的楠姐
    2020-12-12 14:50

    Firstly you need import the bcrypt package

    go get golang.org/x/crypto/bcrypt
    

    Then use GenerateFromPassword

    bs, err := bcrypt.GenerateFromPassword([]byte(p), bcrypt.MinCost)
        if err != nil {
            http.Error(w, "Internal server error", http.StatusInternalServerError)
            return
        }
    

提交回复
热议问题