pws icon indicating copy to clipboard operation
pws copied to clipboard

Add support for alphanumeric/simple password generation

Open alex0112 opened this issue 2 years ago • 2 comments

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:

  • --alphanumeric to generate a password only matching the character class [A-Za0-9a-z]
  • --simple to generate a password only matching the character class [0-9a-zA-Z!@#$%^&*()]

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 avatar Mar 10 '22 07:03 alex0112

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 avatar Mar 10 '22 08:03 alex0112

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:

  • First try excluding quotes, backticks, backslashes etc. with --exclude-strange
  • If that's not successful, try using only the slightly less complex charpool with --simple, and if that one is rejected
  • Default to --alphanumeric and weep salty tears at the state of password policies on whatever service they are using.

alex0112 avatar Mar 10 '22 08:03 alex0112