flowerpassword.rust
Flower Password implementation for Rust - a secure password generator based on master password and key using MD5/HMAC-MD5 hashing.
Overview
This library implements the Flower Password algorithm, which generates secure, deterministic passwords based on:
- A master password (your secret)
- A key (e.g., website domain, service name)
- A desired length (2-32 characters)
The same inputs will always generate the same output, allowing you to recreate passwords without storing them.
Features
- 🔒 Secure: Uses HMAC-MD5 with multiple rounds of hashing
- 🎯 Deterministic: Same inputs always generate the same password
- 📏 Flexible: Password length from 2 to 32 characters
- ✅ Validated: Comprehensive test suite
- 🦀 Pure Rust: No unsafe code, zero dependencies (except
md5crate) - 🔄 Compatible: Produces identical output to the JavaScript implementation
Installation
Add this to your Cargo.toml:
[]
= "1.0"
Usage
Basic Example
use fp_code;
Different Lengths
use fp_code;
Error Handling
use ;
Multiple Services
use fp_code;
API Reference
fp_code
Generates a Flower Password based on master password and key.
Parameters:
password: Master password (any string)key: Domain or service identifier (any string)length: Output password length (2-32 characters)
Returns:
Ok(String): Generated passwordErr(FlowerPasswordError): If length is invalid
Errors:
FlowerPasswordError::InvalidLength: Length is not between 2 and 32
Algorithm
The Flower Password algorithm:
- Generates HMAC-MD5 hash from password and key
- Creates two derivative hashes using fixed salts ("kise" for rules, "snow" for source)
- Applies character transformation rules based on a magic string
- Ensures the first character is always alphabetic
- Returns the password at the requested length
Character Composition
Generated passwords contain:
- Uppercase letters (A-Z)
- Lowercase letters (a-z)
- Digits (0-9)
The first character is always a letter (never a digit).
Testing
Run the test suite:
Run tests with output:
Run doc tests:
Examples
Example outputs for reference:
| Master Password | Key | Length | Generated Password |
|---|---|---|---|
password |
key |
16 | K3A2a66Bf88b628c |
test |
github.com |
16 | D04175F7A9c7Ab4a |
mypassword |
example.com |
12 | K0CA12CecFFB |
secret |
google.com |
16 | Kc6813f75AAa6Bd1 |
Compatibility
This Rust implementation produces identical output to:
- flowerpassword.js v5.0.0+
Security Considerations
⚠️ Important Notes:
- Master Password: Keep your master password secure. If compromised, all generated passwords are compromised.
- MD5 Usage: This algorithm uses MD5 for historical compatibility. While MD5 is not recommended for cryptographic purposes, the Flower Password algorithm applies it in multiple rounds with HMAC, which provides reasonable security for password generation.
- Deterministic: Outputs are deterministic - same inputs always produce same outputs. This is a feature, not a bug.
- No Storage: Passwords are generated on-demand, not stored. If you forget your master password or key, you cannot recover the generated password.
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development
# Run tests
# Run tests with output
# Run clippy (linter)
# Format code
# Build documentation
Releasing
The project uses automated CI/CD with GitHub Actions.
Quick release:
# Using the release script (easiest)
# Or manually with GitHub Actions
# Go to Actions → Manual Release → Run workflow
The release process automatically:
- Runs all tests
- Publishes to crates.io
- Creates a GitHub release
Author
xLsDg xlsdg@qq.com (https://xlsdg.org/)