DEV Community

Cover image for Stateless Password Generator: Secure and Hassle-Free Password Management
Ky Huynh
Ky Huynh

Posted on

Stateless Password Generator: Secure and Hassle-Free Password Management

Managing multiple passwords across various platforms can be daunting. The Stateless Password Generator simplifies this process using a secure, stateless Master Password algorithm. This tool eliminates the need to store passwords while ensuring robust security. It’s available for installation on the Chrome Web Store, operating entirely offline for maximum privacy.

E.g: Generate passwords for Facebook

ui

Key Features

  1. Stateless Operation: No data is stored, and passwords are generated dynamically using your master password.
  2. Customizable Preferences: Adjust password settings, including length and character requirements (uppercase, lowercase, numbers, special characters).
  3. Offline Functionality: No external connections are needed, enhancing security.
  4. Single Master Password: Memorize one master password for all accounts, simplifying password management.

How It Works

The Stateless Password Generator employs a cryptographic hash function to generate unique passwords for each website. The algorithm ensures the generated passwords adhere to the user-defined constraints, such as required character types and maximum length.

Core Algorithm

Here’s a breakdown of the password generation process:

  1. User Input:
  • Domain name
  • Username
  • Master password
  • Additional preferences (e.g., password length, required character types)
  1. Hashing: The inputs are combined into a single string and hashed using the SHA-256 algorithm. This ensures a unique and deterministic hash value for each set of inputs.

  2. Password Construction:

  • Required character rules are extracted from the user’s preferences.
  • The hashed output is mapped to characters from defined sets (e.g., uppercase, lowercase, numbers, special characters).
  • The resulting password satisfies all constraints and is truncated to the specified length.

Code Highlights

Below are key functions that power the Stateless Password Generator:

Define Character Sets

const upperChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const lowerChars = 'abcdefghijklmnopqrstuvwxyz';
const numberChars = '0123456789';
const specialChars = '!@#$%^&*()';
const CHARACTER_SETS = {
    uppercase: upperChars,
    lowercase: lowerChars,
    number: numberChars,
    special: specialChars,
};
Enter fullscreen mode Exit fullscreen mode

Hashing Logic

async function hashPassword(userData) {
    const combinedString = userData.domain + userData.username + userData.masterPassword + userData.pwVersion;
    const encoder = new TextEncoder();
    const passwordHash = await crypto.subtle.digest('SHA-256', encoder.encode(combinedString));
    const passwordHashArray = Array.from(new Uint8Array(passwordHash));

    const allRequiredChars = getRequireChars(getRequireRules(
        userData.isRequiredUpperCase,
        userData.isRequiredLowerCase,
        userData.isRequiredNumber,
        userData.isRequiredSpecial
    ));

    let password = "";
    for (let i = 0; i < userData.maxLength; i++) {
        let byte = passwordHashArray[i % passwordHashArray.length];
        password += allRequiredChars[byte % allRequiredChars.length];
    }
    return password;
}
Enter fullscreen mode Exit fullscreen mode

Character Rule Mapping

function getRequireRules(isRequiredUpperCase, isRequiredLowerCase, isRequiredNumber, isRequiredSpecial) {
    let rules = [];
    if (isRequiredUpperCase) rules.push('uppercase');
    if (isRequiredLowerCase) rules.push('lowercase');
    if (isRequiredNumber) rules.push('number');
    if (isRequiredSpecial) rules.push('special');
    return rules;
}
Enter fullscreen mode Exit fullscreen mode

Benefits

  • Enhanced Security: Passwords are generated locally and never transmitted or stored.
  • Convenience: Only remember your master password to access all generated passwords.
  • Customizable: Tailor password generation to meet stringent security requirements.

Conclusion

The Stateless Password Generator is a powerful tool for managing passwords securely and efficiently. By leveraging cryptographic hashing and stateless algorithms, it offers robust protection without compromising usability. Install it from the Chrome Web Store!

Please checkout the GitHub for more details.

Enjoying the project? Don’t forget to star it ⭐!

Dive into Code

Top comments (0)