The PassGen
class utility designed to facilitate the generation of secure passwords and unique identifiers. It offers various methods for generating cryptographic hashes, secret keys, and unique IDs with customizable complexity levels.
-
hash(key: string): string
- Description: Generates a hash from the provided
key
combined with a timestamp. Returns a string in the specified base (LEVEL
). - Parameters:
key
: The input string to hash.
- Returns: A padded hash string.
- Description: Generates a hash from the provided
-
generateSecret(length: number = 32): string
- Description: Generates a random alphanumeric secret of the specified
length
. - Parameters:
length
(optional): The length of the generated secret (default is 32).
- Returns: A random secret string.
- Description: Generates a random alphanumeric secret of the specified
-
generateID(): string
- Description: Creates a unique identifier combining a hash, a UUID, and a random secret.
- Returns: A string in the format
hashValue-uuidValue-secretKey
.
yarn
to see output
yarn dev
const myPass = new PassGen(16);
const genID = myPass.generateID();
const hashValue = myPass.hash('this is a secret key?');
const secretKey = myPass.generateSecret();
console.log({ genID, hashValue, secretKey, myPass });
{
genID: '-7e9f954b-5794a534-9221-475a-842a-c7e8504fb509-Nprvndx',
hashValue: '2361ad49',
secretKey: 'zp9az7ljTw',
myPass: PassGen { value: 8191, LEVEL: 16, timestamp: 1724038646122n }
}