title: Golang bcrypt hashed passwords dont match
body: <p>so I am storing a password hash in mongodb in example one below. If I add it then retrieve in the same function it says the password and hash match, however if I try to retrieve it in another function, both values are still the same, except the hashed password does not match the supplied password. Example below.</p>
  
  <pre><code>c := session.DB("users").C("accounts")
  
  err = c.Find(bson.M{"username": user.Username}).One(&amp;userInfo)
  if err != nil {
      return err
  }
  
  log.Println(user.Password+Pepper)
  log.Println(userInfo)
  
  err = bcrypt.CompareHashAndPassword(userInfo.PWHash, []byte(user.Password+Pepper))
  if err != nil {
      return err
  }
  return nil
  </code></pre>
  
  <p>The example above the password does not match the hash.</p>
  
  <pre><code>orig := user.Password
  user.PWHash, err = bcrypt.GenerateFromPassword([]byte(user.Password+Pepper), bcrypt.DefaultCost)
  
  session, err := mgo.Dial("mongodb")
  if err != nil {
      return err
  }
  
  defer session.Close()
  
  if InTesting {
      err = session.DB("users").DropDatabase()
      if err != nil {
          return err
      }
  }
  
  c := session.DB("users").C("accounts")
  err = c.Insert(user)
  if err != nil {
      return err
  }
  
  var userInfo models.UserAuth
  err = c.Find(bson.M{"username": user.Username}).One(&amp;userInfo)
  if err != nil {
      return err
  }
  
  log.Println(orig + Pepper)
  log.Println(userInfo)
  
  err = bcrypt.CompareHashAndPassword(userInfo.PWHash, []byte(orig+Pepper))
  if err != nil {
      log.Println(err)
  } else {
      log.Println("matched!")
  }
  </code></pre>
  
  <p>In the example above the passwords do match. Both examples the comments of the 2 logs contain identical information. I have no ideas at all. Any help is greatly appreciated :)</p>