janlelis / pws

Command-Line Password Safe 🔐︎
MIT License
208 stars 19 forks source link

Add support for alphanumeric/simple password generation #24

Open alex0112 opened 2 years ago

alex0112 commented 2 years ago

Problem

I often find myself needing to generate a password where characters such as ' " \ or a backtick are not allowed.

A while back the --exclude flag was added in #23, but I often find myself hitting this scenario:

$ pws gen example-passwd --exclude '\\`\'"'
dquote>

Usually I'm too lazy to figure out the proper quoting conventions for these characters in my current shell, and often my workflow for sites that block characters like these is to do this:

pws gen example-passwd --charpool 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+='

Which works, but is a bit much in terms of manual typing. Even then, sometimes sites will reject some of those characters. So I end up defaulting to:

pws gen example-passwd --charpool 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'

Proposed Solution:

Add two new options:

I've taken the liberty of prototyping a few Gherkin tests about what the end behavior might look like:

Scenario: Generate a new password for "github", using only alphanumeric characters
    Given A safe exists with master password "my_master_password"
    When I run `pws generate github 0 --alphanumeric` interactively
    And I type "my_master_password"
    Then the output should contain "Master password:"
    And the output should contain "The password for github has been added"
    And  the output should contain "The password for github has been copied to your clipboard"
    And  the clipboard should match ^[0-9a-zA-Z]{64}$
Scenario: Generate a new password for "github", using only alphanumeric and no special characters
    Given A safe exists with master password "my_master_password"
    When I run `pws generate github 0 --basic` interactively
    And I type "my_master_password"
    Then the output should contain "Master password:"
    And the output should contain "The password for github has been added"
    And  the output should contain "The password for github has been copied to your clipboard"
    And  the clipboard should match ^[0-9a-zA-Z!@#$%^&*()]{64}$
alex0112 commented 2 years ago

I've been thinking about this feature for a hot minute. Happy to implement it if there's interest and no one else beats me to it.

alex0112 commented 2 years ago

If there's interest in this feature, I'd also like to add another option (which I will write up in a separate issue) that's something like --exclude-strange which would simply exclude some of the commonly disallowed characters mentioned above.

My thought being that when a site disallowing the regular character set is hit, a user can: