1. func genMd5(code string) string {
    2. m := md5.New()
    3. _, _ = io.WriteString(m, code)
    4. return hex.EncodeToString(m.Sum(nil))
    5. }

    go get github.com/anaskhan96/go-password-encoder

    1. //salt, encodedPwd := password.Encode("generic password", nil)
    2. //fmt.Println("salt", salt)
    3. //fmt.Println("encodedPwd", encodedPwd)
    4. //check := password.Verify("generic password", salt, encodedPwd, nil)
    5. //fmt.Println(check) // true
    6. // Using custom options
    7. options := &password.Options{SaltLen: 16, Iterations: 100, KeyLen: 32, HashFunction: sha512.New}
    8. salt, encodedPwd := password.Encode("generic password", options)
    9. passwd := fmt.Sprintf("$pbkdf2-sha512$%s$%s", salt, encodedPwd)
    10. fmt.Println("len(passwd)", len(passwd))
    11. fmt.Println("passwd", passwd)
    12. passwdInfo := strings.Split(passwd, "$")
    13. check := password.Verify("generic password", passwdInfo[2], passwdInfo[3], options)
    14. fmt.Println(check) // true