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