Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627
  1. // Copyright (c) 2018 Shivaram Lingamneni
  2. package irc
  3. import (
  4. "encoding/base64"
  5. "errors"
  6. )
  7. var (
  8. errInvalidPasswordHash = errors.New("invalid password hash")
  9. )
  10. // Decode a hashed passphrase as it would appear in a config file,
  11. // retaining compatibility with old versions of `oragono genpasswd`
  12. // that used to apply a redundant layer of base64
  13. func decodeLegacyPasswordHash(hash string) ([]byte, error) {
  14. // a correctly formatted bcrypt hash is 60 bytes of printable ASCII
  15. if len(hash) == 80 {
  16. // double-base64, remove the outer layer:
  17. return base64.StdEncoding.DecodeString(hash)
  18. } else if len(hash) == 60 {
  19. return []byte(hash), nil
  20. } else {
  21. return nil, errInvalidPasswordHash
  22. }
  23. }