unique-login-credential
NPMA robust, type-safe library to generate unique passwords and usernames.
npm install unique-login-credentialuniquePassword(options)
Generates a unique password based on the provided configuration. You can specify exactly how many of each character type you want in the final output.
| Property | Type | Default | Description |
|---|---|---|---|
| length | number | 8 | Total length of the password. |
| capitalLetter | number | 1 | Minimum number of uppercase letters (A-Z). |
| smallLetter | number | 3 | Minimum number of lowercase letters (a-z). |
| number | number | 2 | Minimum number of digits (0-9). |
| specialCharacter | number | 2 | Minimum number of special characters (!@#$_*). |
| random | boolean | false | Whether to thoroughly shuffle the final output string. |
import { uniquePassword } from 'unique-login-credential';
// Default configuration
const defaultPwd = uniquePassword();
console.log(defaultPwd);
// Custom configuration
const customPwd = uniquePassword({
length: 12,
capitalLetter: 2,
specialCharacter: 1,
random: true
});
console.log(customPwd);uniqueUsername(options)
Combines a user-defined prefix with a randomized alphanumeric suffix according to the supplied configuration.
| Property | Type | Default | Description |
|---|---|---|---|
| prefix | string | "" | The fixed string to prepend to the generated username. |
| length | number | 6 | Total length of the username (including prefix). |
| Also accepts all configuration options from uniquePassword (capitalLetter, smallLetter, etc.) | |||
import { uniqueUsername } from 'unique-login-credential';
// Using a prefix
const user1 = uniqueUsername({
prefix: "admin_",
length: 12,
random: true
});
console.log(user1); // e.g. "admin_2hA9k"