UNPKG

@wepublish/api

Version:
32 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserSort = exports.generateSecureRandomPassword = exports.hashPassword = void 0; const tslib_1 = require("tslib"); const bcrypt_1 = tslib_1.__importDefault(require("bcrypt")); const common_1 = require("./common"); const crypto_1 = require("crypto"); const hashPassword = (password, bcryptHashCostFactor = common_1.DefaultBcryptHashCostFactor) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return bcrypt_1.default.hash(password, bcryptHashCostFactor); }); exports.hashPassword = hashPassword; const generateSecureRandomPassword = (length) => { const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-'; let password = ''; const characterCount = characters.length; const maxValidValue = 256 - (256 % characterCount); while (password.length < length) { const randomValue = (0, crypto_1.randomBytes)(1)[0]; if (randomValue < maxValidValue) { const index = randomValue % characterCount; password += characters.charAt(index); } } return password; }; exports.generateSecureRandomPassword = generateSecureRandomPassword; var UserSort; (function (UserSort) { UserSort["CreatedAt"] = "createdAt"; UserSort["ModifiedAt"] = "modifiedAt"; UserSort["Name"] = "name"; UserSort["FirstName"] = "firstName"; })(UserSort || (exports.UserSort = UserSort = {})); //# sourceMappingURL=user.js.map