title: Bcrypt encryption different every time with same input
body: <p>Using <code>golang.org/x/crypto/bcrypt</code> and GORM (<a href="http://gorm.io/docs/" rel="noreferrer">http://gorm.io/docs/</a>) I'm trying to encrypt a password. The problem is that every encryption of it is different every time, so it can never match the one in the database.</p>
  
  <pre><code>var result []string
  
  password := []byte(data.Password)
  encryptedPassword, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost) // different every time
  
  db.Where(&amp;User{Username: strings.ToLower(data.Username)}).First(&amp;user).Pluck("password", &amp;result)
  encryptionErr := bcrypt.CompareHashAndPassword(encryptedPassword, []byte(result[0]))
  
  if encryptionErr == nil { // passwords match! }
  </code></pre>
  
  <p>I have confirmed that the input is the same every time and that the password given from the database is correct.</p>
  
  <p>What am I doing wrong here?</p>