A lightweight, dependency-free Dart package for generating random passwords made up of lowercase letters, uppercase letters, numbers, and symbols.
Features
- Generates a random password of any requested length.
- Mixes up to four character sets — lowercase, uppercase, numbers, symbols — chosen randomly per character.
- Each character set can be individually enabled or disabled.
- Zero external dependencies (uses only
dart:math). - Simple, single-method API.
Platform support
This package is written in pure Dart — it has no Flutter SDK dependency
and no platform channels, native code, or dart:io/dart:html usage. As a
result it works identically on every platform supported by Dart and Flutter:
| Platform | Supported |
|---|---|
| Android | ✅ |
| iOS | ✅ |
| Web | ✅ |
| Windows | ✅ |
| macOS | ✅ |
| Linux | ✅ |
| Server / CLI (pure Dart) | ✅ |
Because it only depends on dart:math, it can also be used in plain Dart
projects (backend, CLI tools, scripts) that don't depend on Flutter at all.
Getting started
Requires Dart SDK ^3.11.5 (or a Flutter SDK that bundles it).
Add the package to your pubspec.yaml:
dependencies:
flutter_random_password: ^1.0.1
Then run:
dart pub get
# or, in a Flutter project:
flutter pub get
Then import it:
import 'package:flutter_random_password/flutter_random_password.dart';
Usage
import 'package:flutter_random_password/flutter_random_password.dart';
void main() {
final pass = RandomPass();
// Generate a 12-character random password using all character sets.
final password = pass.generate(total: 12);
print(password); // e.g. "aB3!kZ9$mQ2#"
// Generate a numeric-only 6-digit PIN.
final pin = pass.generate(
total: 6,
hasAlphabet: false,
hasAlphabetUpper: false,
hasSymbol: false,
);
print(pin); // e.g. "482913"
}
See example/flutter_random_password_example.dart for a runnable example that
generates 100 passwords of varying length (6–17 characters).
API
RandomPass implements FlutterRandomPasswordBase:
abstract class FlutterRandomPasswordBase {
String generate({
required int total,
bool hasAlphabet,
bool hasNumeric,
bool hasAlphabetUpper,
bool hasSymbol,
});
}
generate(...) returns a random password exactly total characters long,
built from the enabled character sets:
| Parameter | Default | Character set |
|---|---|---|
total |
— | Password length (required) |
hasAlphabet |
true |
Lowercase a-z |
hasAlphabetUpper |
true |
Uppercase A-Z |
hasNumeric |
true |
Digits 0-9 |
hasSymbol |
true |
Symbols !@#$%^&*()_+-={}|[]\:";'>?<,./`~ |
Throws an ArgumentError if:
totalis0or negative, or- every
has*flag isfalse(no character set left to draw from).
Additional information
- Package name is historical (
flutter_random_password) but the package itself has no Flutter dependency — it works in any pure Dart project. - Character composition per generated character is random and independent, so a password is not guaranteed to contain at least one character from every set (e.g. a short password could end up all digits by chance).
- Uses
dart:math's default (non-seeded)Random, which is not cryptographically secure. Do not use this package to generate secrets such as encryption keys, tokens, or anything requiring cryptographic-strength randomness. - Contributions and issues are welcome via the project repository.
License
Licensed under the MIT License © 2026 znd3v (zendevv.com).
Libraries
- flutter_random_password
- A simple library for generating random passwords made up of lowercase letters, uppercase letters, numbers, and symbols.