9951 explained code solutions for 126 technologies


golangHow to generate hash for password


Use bcrypt package (to install run go get golang.org/x/crypto/bcrypt) for hashin passwords:

package main

import (
  "fmt"
  "golang.org/x/crypto/bcrypt"
)

func main() {
  pwd := "qwerty123"
  hash, _ := bcrypt.GenerateFromPassword([]byte(pwd), 10)
  fmt.Println(string(hash))
}ctrl + c
package main

default package declaration

qwerty123

sample password string to hash

bcrypt.GenerateFromPassword

returns hash from given password