go - Bcrypt password hashing in Golang (compatible with Node.js)? -
I have a node for user authentication. I am setting up a site with JS + passport.
Now I need to move to the sphere, and need to authenticate with saved user password in DB.
The node. JS encryption code is:
var bcrypt = require ('bcrypt'); bcrypt.genSalt (10, function (hey, salt) {if (mistake) return next (mistake); bcrypt.hash (user.password, salt, function (hey, hash) {if (mistake) next return (mistake); User.password = hash; next ();});}); How to make the same piece of string in Node.js bcrypt with Golang?
After using the text "itemprop =" text ">
package, I believe the equivalent will be:
hashedPassword, hey: = bcrypt.GenerateFromPassword (password, bcrypt.DefaultCost) Task example: package Main import ("golang.org/x/crypto/bcrypt" "fmt") func main () {password: = [] Byte ("MyDarkSecret") // hashingPassword, hashing password with default cost of heaving: = bcrypt .generateFromPassword (password, bcrypt.DefaultCost) if Anne = Nil {Terror (mistake)} fmt.Println (string hashedPassword) // hash Anm = bcrypt.CompareHashAndPassword (hashedPassword, password (Compare) password with fmt.println (mistake) // zero it means a match}
Comments
Post a Comment