An open API service indexing awesome lists of open source software.

https://github.com/christopheralphonse/passgen

Created this for fast ID creation for personal projects
https://github.com/christopheralphonse/passgen

passgenerator security uuid

Last synced: about 1 year ago
JSON representation

Created this for fast ID creation for personal projects

Awesome Lists containing this project

README

          

# **PassGen**

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.

### Methods

- **`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.

- **`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.

- **`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`.

## Running the code

```bash
yarn
```
*to see output*
```bash
yarn dev
```
## Usage Example
```js
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 });
```

```bash
{
genID: '-7e9f954b-5794a534-9221-475a-842a-c7e8504fb509-Nprvndx',
hashValue: '2361ad49',
secretKey: 'zp9az7ljTw',
myPass: PassGen { value: 8191, LEVEL: 16, timestamp: 1724038646122n }
}
```