Flutter密码生成插件passwd_gen_cli的使用
Flutter密码生成插件passwd_gen_cli的使用
安装
从源码安装
你需要安装Dart SDK。你可以通过以下命令获取源码:
git clone https://gitlab.com/kurdy/passwd-gen-cli.git
在源码目录的根目录下执行以下命令来启动守护进程并运行测试:
# 启动守护进程
dart run passwd_gen_cli --daemon -f "emoji|test/emoji-items.txt" &
# 运行测试
dart test
如果所有测试都通过,你会看到类似如下的输出:
00:10 +28 ~1: All tests passed!
编译并构建应用:
dart compile exe ./bin/passwd_gen_cli.dart -o ./build/passwd_gen_cli
使用指南
你可以在项目的Wiki页面上找到更多示例和文档:
命令行用法
显示版本信息
passwd_gen -v
结果:
passwd_gen_cli 1.0.2
获取帮助信息
passwd_gen_cli -h
结果:
Application to generate passwords or a phrase composed of several words.
It's possible to use one or more collections of items as source to create them.
USAGE:
passwd_gen_cli [FLAGS] [OPTIONS]...
passwd_gen_cli Will create one password with default parameters
FLAGS:
-d, --daemon Start a long-running daemon process.
Use -h, --help with daemon to learn more about http daemon server.
-e, --entropy Display entropy.
-o, --noColor Don't use color to display result.
-h, --help Print a help message
-l, --license Prints license information
-v, --version Prints version information
OPTIONS:
-c, --collection latin or french or german or spanish or italian or eff
-s, --size password size default=15
-n, --number number of password to generate default=1
-f, --file Text file with items (one item per line)
-x, --exclude List of excluded items separated by ,
EXIT STATUS:
The CLI will exit with one of the following values:
0 Successful execution.
1 Failed executions.
使用守护进程
passwd_gen_cli --daemon -h
结果:
USAGE:
daemon start a basic web server. With UI on http://localhost:{port}/
passwd_gen_cli [--daemon | -d] [--port | -p]
OPTIONS:
-p, --port port number > 1024, default=4040
-f, --file Text file with items (one item per line)
It can be file or key|file. Examples: -f ./path/foo.txt or -f mywords|./path/foo.txt
-i, --index Allows to provide an alternative version of the HTML content.
REQUESTS:
http://localhost:{port}/generate/{collection}?parameters
collection : default = latin
size : default = 15
number : default = 1
json : otherwise text
exclude : as string, items are separated by comma
http://localhost:{port}/license ➜ show license.
http://localhost:{port}/version ➜ show application version.
http://localhost:{port}/collections ➜ json with id's of custom items
http://localhost:{port}/stop ➜ Stop daemon.
http://localhost:{port} ➜ show web UI.
Examples:
http://localhost:4040/generate/french?size=29&number=10&json
http://localhost:4040/stop ➜ Stop daemon.
创建密码
使用默认设置创建密码
passwd_gen
这些命令是等效的,因为它们使用的是默认设置。
passwd_gen --collection latin --size 15
结果:
Yi72ehayU[{4|Yg
使用不同的集合创建密码
passwd_gen --collection french;
passwd_gen -c german;
passwd_gen -c italian;
结果:
1wZLM1j+ùï9>èw?
使用EFF的词表创建短语
passwd_gen --collection eff;
结果:
marbling anemia tartar lifter opal elevation underhand vengeful exemplary guts blooper vicinity improvise sheet amber
使用自定义文件创建短语
使用单个文件
passwd_gen --file ./test/eduscol_fr.txt;
结果:
liberté mouvement famille combat descendre presque rencontrer serrer forêt principe société enfance troubler promener prononcer
使用多个文件
passwd_gen --file ./test/katakana-items.txt;
结果:
ゲン・ヘヅポヲジヶクワグヌユギ
使用两个文件
passwd_gen --file ./test/katakana-items.txt --file ./test/emoji-items.txt;
结果:
😨ル🙇ュチピ😖🙊ォ😎😯😆ウ😕ブ
生成多个密码
passwd_gen --number 10;
结果:
X,@ej@9K16qpjrQ
6JgjvFc\\4n]Wf9
5daX£6jo=Kd'5Vj
6"dU#zT3oy6Mq!k
w€uZD3zt9[K:7si
0d-gu2XTZb$$b8p
Id1|srP'5h,8dhL
sc?Y9j,sDi'k49P
v4,rXuh:l8NT~i6
h+f0m5d+-IyXu5J
生成具有熵值的密码
passwd_gen --size 25 -e
结果:
YfveD4396"[WL6F0_&\p-\qGgj
Bits of entropy 164
排除某些字符
passwd_gen -c french --exclude 'ô,ù,û,ü,ÿ,æ,œ,«,»,’,i,l,1' -s 29;
结果:
d8véB+î5xë7m'cz|ao8*YWR9êî£eA
使用守护进程
passwd_gen --daemon -f "emoji|test/emoji-items.txt";
结果:
Starting server ....
Server started waiting a request. InternetAddress('127.0.0.1', IPv4) port 4040
Open url : http://127.0.0.1:4040
默认URL为:
http://127.0.0.1:4040
更多关于Flutter密码生成插件passwd_gen_cli的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter密码生成插件passwd_gen_cli的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
passwd_gen_cli
是一个用于生成随机密码的 Flutter 插件。它可以在命令行界面 (CLI) 中使用,也可以集成到 Flutter 应用中。以下是如何使用 passwd_gen_cli
插件的基本步骤:
1. 安装插件
首先,你需要在 pubspec.yaml
文件中添加 passwd_gen_cli
插件的依赖:
dependencies:
passwd_gen_cli: ^1.0.0 # 请使用最新版本
然后运行 flutter pub get
来安装插件。
2. 在命令行中使用
如果你在命令行中使用 passwd_gen_cli
,可以直接调用插件提供的命令来生成密码。
flutter pub run passwd_gen_cli:generate_password --length=12 --include-numbers --include-symbols
这个命令会生成一个长度为 12 的密码,包含数字和特殊符号。
3. 在 Flutter 应用中使用
你也可以在 Flutter 应用中使用 passwd_gen_cli
插件来生成密码。
首先,导入插件:
import 'package:passwd_gen_cli/passwd_gen_cli.dart';
然后,使用 generatePassword
方法来生成密码:
void main() {
String password = generatePassword(
length: 12,
includeNumbers: true,
includeSymbols: true,
);
print('Generated Password: $password');
}
4. 参数说明
generatePassword
方法接受以下参数:
length
: 密码的长度(默认值为 8)。includeNumbers
: 是否包含数字(默认值为false
)。includeSymbols
: 是否包含特殊符号(默认值为false
)。includeUppercase
: 是否包含大写字母(默认值为true
)。includeLowercase
: 是否包含小写字母(默认值为true
)。
5. 示例
以下是一个完整的示例,展示了如何在 Flutter 应用中使用 passwd_gen_cli
插件:
import 'package:flutter/material.dart';
import 'package:passwd_gen_cli/passwd_gen_cli.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Password Generator',
home: PasswordGeneratorScreen(),
);
}
}
class PasswordGeneratorScreen extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
String password = generatePassword(
length: 12,
includeNumbers: true,
includeSymbols: true,
);
return Scaffold(
appBar: AppBar(
title: Text('Password Generator'),
),
body: Center(
child: Text('Generated Password: $password'),
),
);
}
}