Core components of the web application. https://write.as
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
546 B

  1. package auth
  2. import "golang.org/x/crypto/bcrypt"
  3. func clear(b []byte) {
  4. for i := 0; i < len(b); i++ {
  5. b[i] = 0
  6. }
  7. }
  8. func HashPass(password []byte) ([]byte, error) {
  9. // Clear memory where plaintext password was stored.
  10. // http://stackoverflow.com/questions/18545676/golang-app-engine-securely-hashing-a-users-password#comment36585613_19828153
  11. defer clear(password)
  12. // Return hash
  13. return bcrypt.GenerateFromPassword(password, 12)
  14. }
  15. func Authenticated(hash, pass []byte) bool {
  16. return bcrypt.CompareHashAndPassword(hash, pass) == nil
  17. }