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.

dummy.go 842B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package hash
  4. import (
  5. "encoding/hex"
  6. )
  7. // DummyHasher implements PasswordHasher and is a dummy hasher that simply
  8. // puts the password in place with its salt
  9. // This SHOULD NOT be used in production and is provided to make the integration
  10. // tests faster only
  11. type DummyHasher struct{}
  12. // HashWithSaltBytes a provided password and salt
  13. func (hasher *DummyHasher) HashWithSaltBytes(password string, salt []byte) string {
  14. if hasher == nil {
  15. return ""
  16. }
  17. if len(salt) == 10 {
  18. return string(salt) + ":" + password
  19. }
  20. return hex.EncodeToString(salt) + ":" + password
  21. }
  22. // NewDummyHasher is a factory method to create a DummyHasher
  23. // Any provided configuration is ignored
  24. func NewDummyHasher(_ string) *DummyHasher {
  25. return &DummyHasher{}
  26. }