GenratrAPI is a simple web service built using Node.js that allows you to generate random passwords with varying degrees of complexity. You can customize the password strength by specifying the character sets you want to include (special characters, lowercase letters, uppercase letters, and numbers) and the desired password length.
- β‘ Rebuilt using native
httpmodule β no Express, Helmet, or middleware overhead - π§ Ultra-fast in-memory index.html β zero disk I/O, Brotli-compressed at startup
- π Manual security headers β including CORS, XSS protection, and MIME sniffing
- π¨ Brotli compression for JSON responses β saves bandwidth without slowdowns
- π§± Modular codebase β split into
routes,utils, andlib
- Node.js and npm installed on your machine.
- Clone this repository to your local machine.
- Navigate to the project directory in your terminal.
- Run
npm installto install the required dependencies.
- Start the server by running
npm startornode server.js. - The server will listen on port 8080 by default. You can change the port by setting the
PORTenvironment variable.
git clone <this-repo>npm installnpm start- URL:
/ - Method: GET
special: Include special characters in the password.lowercase: Include lowercase letters in the password.uppercase: Include uppercase letters in the password.numbers: Include numbers in the password.length: Desired length of the password (integer, default is 12).
Trying to generate a password without specifying any strength settings:
curl "http://localhost:8080/?length=10"{
"error": "Invalid request"
}Generate a password with specific settings (20 characters, includes special characters, lowercase and uppercase letters, and numbers):
curl "http://localhost:8080/?length=16&uppercase&lowercase&special&numbers"{
"password": "ZTd,BCsj2.$uk^4}!R%5"
}genratr provides a function that generates random passwords based on your preferences. You can specify which types of characters to include in the password.
Here's how you can use the genratr function in your project:
- Import the
genratrfunction
const genratr = require("./lib/genratr");- Call the
genratrfunction with an object containing your preferences. You can specify the character sets you want to include and the desired length of the password. For example:
const passwordOptions = {
special: true, // Include special characters
lowercase: true, // Include lowercase letters
uppercase: true, // Include uppercase letters
numbers: true, // Include numbers
length: 16, // Set the desired password length (optional, defaults to 12)
};
const password = genratr(passwordOptions);
console.log("Generated Password:", password);<form action="/" method="get">
<label> <input type="checkbox" name="special" /> Special characters </label>
<label>
<input type="checkbox" name="lowercase" /> Lowercase characters
</label>
<label>
<input type="checkbox" name="uppercase" /> Uppercase characters
</label>
<label> <input type="checkbox" name="numbers" /> Numbers </label>
<label>
Length:
<input type="number" name="length" value="12" />
</label>
<button type="submit">Generate Password</button>
</form>
<p>Password: <span id="password"></span></p>
<script>
const form = document.querySelector("form");
const passwordSpan = document.getElementById("password");
form.addEventListener("submit", async (event) => {
event.preventDefault();
const formData = new FormData(form);
const params = new URLSearchParams(formData).toString();
const response = await fetch(`/?${params}`);
const data = await response.json();
passwordSpan.textContent = data.password;
});
</script>