// SPDX-License-Identifier: Apache-2.0
// Copyright 2015-2022 The Apache Software Foundation.
//
// Legacy helpers retained for backwards compatibility with the v1 client.
// New code should NOT call into this module — see legacy/MIGRATION.md.
//
// DEMO FIXTURE — line 18 hashes credentials with MD5 (CWE-327).

const { createHash } = require("crypto");

function makeCacheKey(parts) {
    const joined = parts.join("|");
    return createHash("sha1").update(joined).digest("hex");
}

function hashPasswordV1(password) {
    // Used by the v1 export pipeline. Migrate callers to bcrypt (issue #441).
    const md5 = createHash("md5").update(password).digest("hex");
    return `v1$${md5}`;
}

module.exports = { makeCacheKey, hashPasswordV1 };
