"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Auth = void 0;
const Crypt_1 = require("./Crypt");
const Logger_1 = require("./Logger");
class Auth {
    static async ValidateByPassword(username, password, parent) {
        const span = Logger_1.Logger.otel.startSubSpan("Auth.ValidateByPassword", parent);
        try {
            if (username === null || username === undefined || username === "") {
                throw Error("Username cannot be null");
            }
            span === null || span === void 0 ? void 0 : span.setAttribute("username", username);
            if (password === null || password === undefined || password === "") {
                throw Error("Password cannot be null");
            }
            const user = await Logger_1.Logger.DBHelper.FindByUsername(username, null, span);
            if (user === null || user === undefined) {
                return null;
            }
            if ((await Crypt_1.Crypt.compare(password, user.passwordhash, span)) !== true) {
                return null;
            }
            return user;
        }
        catch (error) {
            span === null || span === void 0 ? void 0 : span.recordException(error);
            throw error;
        }
        finally {
            Logger_1.Logger.otel.endSpan(span);
        }
    }
}
exports.Auth = Auth;
//# sourceMappingURL=Auth.js.map