UNPKG

@hixbe/otp-pass-kit

Version:

A secure, cryptographically-strong OTP and password generator for Node.js with CLI support. Generate customizable one-time passwords and strong passwords with TypeScript support.

1 lines 1.73 kB
"use strict";var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,o={};((e,r)=>{for(var n in r)t(e,n,{get:r[n],enumerable:!0})})(o,{generateOtp:()=>b,generatePass:()=>g}),module.exports=(e=o,((e,o,a,l)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let p of n(o))s.call(e,p)||p===a||t(e,p,{get:()=>o[p],enumerable:!(l=r(o,p))||l.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a=require("crypto"),l="0123456789",p="abcdefghijklmnopqrstuvwxyz",c="ABCDEFGHIJKLMNOPQRSTUVWXYZ",i="!@#$%^&*()_+-=[]{}|;:,.<>?";function u(e){if(!Number.isInteger(e)||e<=0)throw new Error("Length must be a positive integer");if(e>1e3)throw new Error("Length cannot exceed 1000 characters")}function h(e){let t="";if(e.digits&&(t+=l),e.lowerCaseAlphabets&&(t+=p),e.upperCaseAlphabets&&(t+=c),e.specialChars&&(t+=i),!t)throw new Error("At least one character set must be enabled");return t}function f(e,t,r){const n=new Array(e);if(r?.ensureEachType&&e>=4){const s=[];r.digits&&s.push(l),r.lowerCaseAlphabets&&s.push(p),r.upperCaseAlphabets&&s.push(c),r.specialChars&&s.push(i);for(let t=0;t<s.length&&t<e;t++){const e=s[t];n[t]=e[(0,a.randomInt)(0,e.length)]}for(let r=s.length;r<e;r++){const e=(0,a.randomInt)(0,t.length);n[r]=t[e]}for(let t=e-1;t>0;t--){const e=(0,a.randomInt)(0,t+1);[n[t],n[e]]=[n[e],n[t]]}}else for(let r=0;r<e;r++){const e=(0,a.randomInt)(0,t.length);n[r]=t[e]}return n.join("")}function b(e=6,t){u(e);const r={lowerCaseAlphabets:!1,upperCaseAlphabets:!1,specialChars:!1,digits:!0,...t};return f(e,h(r),r)}function g(e=8,t){u(e);const r={lowerCaseAlphabets:!0,upperCaseAlphabets:!0,specialChars:!0,digits:!0,...t};return f(e,h(r),r)}