Validate checks if the hash matches the plaintext.
(hashed, plain string)
| 83 | |
| 84 | // Validate checks if the hash matches the plaintext. |
| 85 | func Validate(hashed, plain string) (bool, error) { |
| 86 | parts := strings.SplitN(hashed, "$", 2) |
| 87 | |
| 88 | if len(parts) < 2 { |
| 89 | return false, errInvalidHash.New() |
| 90 | } |
| 91 | |
| 92 | typ := parts[0] |
| 93 | |
| 94 | for _, method := range hashValidators { |
| 95 | if strings.EqualFold(typ, method.Name()) { |
| 96 | return method.Validate(hashed, plain) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | return false, errUnknownHashingMethod.WithAttributes("method", typ) |
| 101 | } |