I use the bcrypt.GenerateFromPassword () method to encrypt, but it is different every time. How should I save the database?

I use the bcrypt.GenerateFromPassword () method to encrypt, but it is different every time. How should I save the database?

package main

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

func main() {
    password := []byte("MyDarkSecret")

    // Hashing the password with the default cost of 10
    hashedPassword, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
    if err != nil {
        panic(err)
    }
    fmt.Println(string(hashedPassword))

    // Comparing the password with the hash
    err = bcrypt.CompareHashAndPassword(hashedPassword, password)
    fmt.Println(err) // nil means it is a match
}
Oct.14,2021

because bcrypt encryption uses random salt, the result of each hash of the same string is different.

If you save

, just convert the result into a string and store it. You can update it if you want. Anyway, the encryption results of the same string are all equivalent

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf47b2-31f1a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf47b2-31f1a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?