DEV Community

Cover image for Secure Passwords, Tokens, and Data Masking in Python - A Toolkit for the AI Era
Krishna Tadi
Krishna Tadi

Posted on

Secure Passwords, Tokens, and Data Masking in Python - A Toolkit for the AI Era

Random Password Toolkit - Secure Passwords, Tokens, and Data Masking for Python Developers

Managing passwords, tokens, API keys, and sensitive data is a common challenge for developers, especially in AI, RAG, and IoT applications. random-password-toolkit is a Python library that simplifies this by providing a complete, production-ready toolkit for secure credential management.


Features

Password Features

Feature Description
Random Password Generation Generate strong and secure passwords.
Generate Multiple Passwords Create multiple passwords in bulk.
Pronounceable Passwords Generate passwords easier to read and pronounce.
Custom Password Generation Use a custom pool of characters.
Password Strength Checker Evaluate passwords with actionable feedback.
Password Encryption & Decryption Secure passwords with AES-256 encryption.
Customizable Options Fully customizable password generation settings.

Random Number Generator Features

Feature Description
Exact Length Random Numbers Generate numbers of any specified length.
Multiple Numbers at Once Generate multiple numbers in one call.
Prefix and Suffix Support Add custom prefixes or suffixes.
String Formatting Return numbers as zero-padded strings.
Flexible Usage Use via a simple function or class.
Lightweight & Production-ready Fast generation without memory overhead.

Token & API Key Features

Feature Description
Secure Token Generation Cryptographically secure tokens using Pythonโ€™s secrets module.
Multiple Token Types Supports access, refresh, and generic tokens.
Expiry Support Define expiration time with built-in validation.
API Key Generator Generate secure keys with configurable bit strength.
Optional Prefix & Suffix Environment-specific identifiers.
Reset Token Generation Secure hash-based tokens for password resets.
Expiry Validation Easily check if a token or key is expired.

Data Masking Features

Feature Description
Email Masking Protect sensitive emails (e.g., t***@example.com).
Phone Masking Hide sensitive digits in phone numbers.
Custom Data Masking Mask any string with configurable visible portions.
Partial Masking Mask specific sections using index ranges.
Privacy Utilities Useful for logs, UI display, and data protection.

Benefits

  • Security: Generate highly secure passwords, tokens, API keys, and unique numbers.
  • Flexibility: Customize generation and masking to suit any application.
  • Ease of Use: Simple, intuitive API for beginners and advanced users.
  • Compatibility: Works seamlessly in Python projects.
  • Encryption & Decryption: Securely store and retrieve passwords.
  • Token Management: Manage tokens with expiry support.
  • API Key Control: Create structured, secure API keys for production.
  • Data Privacy: Protect sensitive information with masking utilities.
  • Random Numbers: Generate secure IDs or codes with custom formatting in bulk.

Installation

Ensure Python 3.6+ is installed. Then install via pip:

pip install random-password-toolkit
Enter fullscreen mode Exit fullscreen mode

Options

Password Generation Options

Option Type Description Default
length Integer Length of the password. 10
numbers Boolean Include numbers in the password. false
symbols Boolean Include symbols in the password. false
lowercase Boolean Include lowercase letters. true
uppercase Boolean Include uppercase letters. true
excludeSimilarCharacters Boolean Exclude similar characters (e.g., 'i', 'l'). false
exclude String Characters to exclude from the password. ''
strict Boolean Enforce at least one character from each pool. false

Random Number Generation Options

Option Type Description Default
length Integer Number of digits in the generated number. 6
count Integer How many numbers to generate at once. 1
as_string Boolean Return numbers as zero-padded strings instead of integers. false
prefix String Optional string to prepend to each generated number. ''
suffix String Optional string to append to each generated number. ''

Token Generation Options

Option Type Description Default
token_type String Type of token: generic, access, refresh. generic
length Integer Length of the generated token. 32
expiry_seconds Integer / Float Expiry time in seconds (auto-set for access/refresh if not given). None
prefix String (Optional) Optional prefix to prepend to token. ''
suffix String (Optional) Optional suffix to append to token. ''

API Key Generation Options

Option Type Description Default
bits Integer Strength of the API key (128, 256, 512, 1024, 2048). 256
char_type String Character set: letters, numbers, alphanumeric, mixed. mixed
separator String (Optional) Character used to separate groups (e.g., -). None
group_size Integer Number of characters per group when using separator. 4
expiry_seconds Integer / Float Expiry time for the API key in seconds. None
prefix String (Optional) Optional prefix to prepend to API key. ''
suffix String (Optional) Optional suffix to append to API key. ''

Data Masking Options

Option Type Description Default
visible_start Integer Number of characters to keep visible at the start. 2
visible_end Integer Number of characters to keep visible at the end. 2
mask_char String Character used for masking. '*'
start Integer Start index for partial masking. 0
end Integer End index for partial masking. None

๐Ÿ’ก Where You Can Use Random Password Toolkit

random-password-toolkit is versatile and production-ready. Here are key areas where it can be applied, highlighting AI, RAG, and security-focused workflows:

1. AI, ML & RAG Applications

  • Credential Management for AI Services: Generate strong API keys and tokens for AI pipelines, RAG systems, or ML dashboards.
  • Automated Token Rotation: Quickly rotate access and refresh tokens for AI workflows.
  • Secure Multi-User AI Systems: Ensure unique, strong passwords for AI dashboards or collaborative ML platforms.
  • Data Masking for AI/ML Training: Protect sensitive datasets when preparing AI or ML training data.
  • Random IDs for AI Experiments: Generate unique numeric or alphanumeric IDs for models, experiments, and automated workflows.

2. Web & Mobile Applications

  • User authentication: Generate strong passwords and secure login credentials.
  • OTPs & temporary passwords: Quickly generate one-time or temporary access credentials.

3. E-commerce & SaaS Platforms

  • Order and invoice numbers: Generate unique, zero-padded IDs.
  • Discount codes & subscription IDs: Create secure, random codes for promotions and subscriptions.

4. Databases & Backend Systems

  • Unique numeric identifiers: Generate sequential or random IDs for records.
  • Batch data generation: Produce bulk test data or production-ready identifiers.

5. Security & IT Systems

  • Password management: Generate strong, encrypted passwords.
  • API keys and tokens: Secure token generation with expiry and prefix/suffix support.
  • Temporary credentials: Create short-lived tokens or passwords for safe access.

6. QA & Testing

  • Automated test data: Generate passwords, tokens, and numbers for testing.
  • Simulations & mock data: Create realistic datasets for staging or CI/CD pipelines.

7. Educational & Research Use

  • Teaching secure password generation: Demonstrate cryptography best practices.
  • Cryptography demos & numeric datasets: Use in educational projects or research experiments.

8. Business & Operations

  • Shipment tracking & inventory codes: Generate secure, unique identifiers.
  • Survey or contest codes: Create bulk random codes for promotions or campaigns.

9. Developer Tools & Automation

  • CLI tools & pipelines: Auto-generate credentials, tokens, or IDs in scripts.
  • CI/CD automation: Integrate password and token generation into development workflows.

We'd love to hear from you and see how you're using Random Password Toolkit in your AI, RAG, or other projects!

Top comments (0)