Skip to content

Commit 0be0eaf

Browse files
authored
Merge pull request #226 from kaniamutan14/feat-password-gen
feat: add zero-dependency password-gen-win package
2 parents 7dd4d94 + 085a47c commit 0be0eaf

3 files changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Password Generator (Windows)
2+
3+
A powerful, zero-dependency Espanso package for generating random passwords instantly. Designed specifically for Windows, it leverages native PowerShell to generate secure strings, paste them into your active window, and automatically save them to your clipboard.
4+
5+
## Features
6+
7+
-**Smart Triggers**: Specify your desired length directly in the trigger.
8+
- 📋 **Auto-Clipboard**: Every generated password is automatically copied to your Windows clipboard for easy use in secondary fields (like "Confirm Password").
9+
- 🔒 **Secure**: Generates unpredictable strings using native system libraries.
10+
- 🚀 **Zero Dependencies**: Works out-of-the-box on Windows using built-in PowerShell.
11+
12+
---
13+
14+
## How to Use
15+
16+
Simply type a trigger followed by the **2-digit length** you want.
17+
18+
> **Important:** The length must always be **two digits**. For lengths less than 10, use a leading zero (e.g., `08` instead of `8`).
19+
20+
### 1. Available Triggers
21+
22+
| Trigger | Complexity | Character Set | Example |
23+
| :------------- | :----------- | :---------------------------------------- | :------- |
24+
| `:pw[length]` | **Standard** | Letters (A-Z, a-z) + Numbers (0-9) | `:pw12` |
25+
| `:pws[length]` | **Secure** | Letters + Numbers + **Symbols** (!@#$...) | `:pws16` |
26+
| `:pwn[length]` | **Numeric** | **Numbers only** (PIN style) | `:pwn06` |
27+
28+
### 2. Practical Examples
29+
30+
- Typing **`:pw12`** results in: `a7B2k9L1p4Xz`
31+
- Typing **`:pws20`** results in: `k#9!2L$p*7xQ9^mN2@5z`
32+
- Typing **`:pwn04`** results in: `8293` (Perfect for quick PINs!)
33+
34+
---
35+
36+
## Why Two Digits?
37+
38+
To ensure maximum speed and reliability, this package waits for exactly two digits after the prefix. This prevents the trigger from firing "too early" (e.g., firing on `:pw2` before you have time to type the `0` for `:pw20`).
39+
40+
## Installation
41+
42+
```
43+
espanso package install password-gen-win
44+
```
45+
46+
## Requirements
47+
48+
- **Operating System**: Windows
49+
- **Engine**: PowerShell Version 5.1 (Built-in)
50+
51+
## Platform Compatibility
52+
53+
While designed for Windows, this package also works on **macOS and Linux** with [PowerShell 7](https://github.com/PowerShell/PowerShell) (`pwsh`) installed. To enable this, either:
54+
55+
- Change `shell: powershell` to `shell: pwsh` in `package.yml`, or
56+
- Symlink `powershell` to `pwsh` on your system.
57+
> **Note for Linux users:** `Set-Clipboard` functionality to copy the password to clipboard may or may not work.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: password-gen-win
2+
title: Password Generator (Windows)
3+
description: Generate random passwords of any length (up to 99) and automatically copy to clipboard. Optimized for Windows with native PowerShell.
4+
version: 0.1.0
5+
author: kaniamutan14
6+
homepage: https://github.com/kaniamutan14/
7+
tags:
8+
- utility
9+
- security
10+
- windows
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/espanso/espanso/dev/schemas/match.schema.json
2+
3+
matches:
4+
- regex: ':pw(?P<mode>s|n|)(?P<len>\d{2})'
5+
replace: "{{output}}"
6+
vars:
7+
- name: output
8+
type: shell
9+
params:
10+
cmd: |
11+
$mode = '{{mode}}'
12+
$chars = switch ($mode) {
13+
's' { 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{}|;:,.<>?' }
14+
'n' { '0123456789' }
15+
default { 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' }
16+
}
17+
$len = [int]('{{len}}')
18+
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
19+
$limit = 256 - (256 % $chars.Length)
20+
$result = New-Object System.Text.StringBuilder
21+
$buf = New-Object byte[] 1
22+
while ($result.Length -lt $len) {
23+
$rng.GetBytes($buf)
24+
if ($buf[0] -lt $limit) { [void]$result.Append($chars[$buf[0] % $chars.Length]) }
25+
}
26+
$pw = $result.ToString()
27+
$rng.Dispose()
28+
Set-Clipboard -Value $pw
29+
Write-Output $pw
30+
shell: powershell

0 commit comments

Comments
 (0)