Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Merge pull request #697 from lastpass/improve-generation" #699

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Revert "Merge pull request #697 from lastpass/improve-generation"
This reverts commit 38d26df, reversing
changes made to 73a1ec8.
  • Loading branch information
mateusmartins-lp committed Aug 7, 2024
commit 40e256335a04a7772c826b3fc5498c9af7b8f240
13 changes: 7 additions & 6 deletions cmd-generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

static char chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?";
#define ALL_CHARS_LEN (sizeof(chars) - 1)
#define MIN_PW_LENGTH 12
#define NICE_CHARS_LEN 62

int cmd_generate(int argc, char **argv)
{
Expand All @@ -57,13 +57,15 @@ int cmd_generate(int argc, char **argv)
{"sync", required_argument, NULL, 'S'},
{"username", required_argument, NULL, 'U'},
{"url", required_argument, NULL, 'L'},
{"no-symbols", no_argument, NULL, 'X'},
{"clip", no_argument, NULL, 'c'},
{0, 0, 0, 0}
};
int option;
int option_index;
char *username = NULL;
char *url = NULL;
bool no_symbols = false;
unsigned long length;
char *name;
enum blobsync sync = BLOB_SYNC_AUTO;
Expand All @@ -83,6 +85,9 @@ int cmd_generate(int argc, char **argv)
case 'L':
url = xstrdup(optarg);
break;
case 'X':
no_symbols = true;
break;
case 'c':
clip = true;
break;
Expand All @@ -96,18 +101,14 @@ int cmd_generate(int argc, char **argv)
die_usage(cmd_generate_usage);
name = argv[optind];
length = strtoul(argv[optind + 1], NULL, 10);

if (!length)
die_usage(cmd_generate_usage);

if (length < MIN_PW_LENGTH)
die("Minimum password length is %d characters.", MIN_PW_LENGTH);

init_all(sync, key, &session, &blob);

password = xcalloc(length + 1, 1);
for (size_t i = 0; i < length; ++i)
password[i] = chars[range_rand(0, ALL_CHARS_LEN)];
password[i] = chars[range_rand(0, no_symbols ? NICE_CHARS_LEN : ALL_CHARS_LEN)];

found = find_unique_account(blob, name);
if (found) {
Expand Down
2 changes: 1 addition & 1 deletion cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int cmd_edit(int argc, char **argv);
#define cmd_edit_usage "edit [--sync=auto|now|no] [--non-interactive] " color_usage " {--name|--username|--password|--url|--notes|--field=FIELD} {NAME|UNIQUEID}"

int cmd_generate(int argc, char **argv);
#define cmd_generate_usage "generate [--sync=auto|now|no] [--clip, -c] [--username=USERNAME] [--url=URL] {NAME|UNIQUEID} LENGTH"
#define cmd_generate_usage "generate [--sync=auto|now|no] [--clip, -c] [--username=USERNAME] [--url=URL] [--no-symbols] {NAME|UNIQUEID} LENGTH"

int cmd_duplicate(int argc, char **argv);
#define cmd_duplicate_usage "duplicate [--sync=auto|now|no] " color_usage " {UNIQUENAME|UNIQUEID}"
Expand Down
5 changes: 5 additions & 0 deletions contrib/completions-lpass.fish
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ complete -f -c lpass -n '__lpass_using_command add edit' \
-l non-interactive \
-d 'Use standard input instead of $EDITOR'

# --no-symbols
complete -f -c lpass -n '__lpass_using_command generate' \
-l no-symbols \
-d 'No symbols'

# --note-type=NOTETYPE
complete -f -c lpass -n '__lpass_using_command add' \
-r -l note-type \
Expand Down
2 changes: 1 addition & 1 deletion contrib/lpass_bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ __lpass_complete_opt()
opts="--sync --non-interactive --name --username --password --url --notes --field --color"
;;
generate)
opts="--sync --clip --username --url --color"
opts="--sync --clip --username --url --no-symbols --color"
;;
share)
opts="--read_only --hidden --admin"
Expand Down
3 changes: 2 additions & 1 deletion contrib/lpass_zsh_completion
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ _lpass() {
_arguments : \
'(-c --clip)'{-c,--clip}'[Copy output to clipboard]' \
'--username=[USERNAME]' \
'--url=[URL]'
'--url=[URL]' \
'--no-symbols[Do not use symbols]'
has_sync=1
;;
status)
Expand Down
2 changes: 1 addition & 1 deletion lpass.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ several subcommands:
lpass *mv* [--sync=auto|now|no] [--color=auto|never|always] {UNIQUENAME|UNIQUEID} GROUP
lpass *add* [--sync=auto|now|no] [--non-interactive] {--name|--username, -u|--password, -p|--url|--notes|--field=FIELD|--note-type=NOTETYPE} [--color=auto|never|always] {NAME|UNIQUEID}
lpass *edit* [--sync=auto|now|no] [--non-interactive] {--name|--username, -u|--password, -p|--url|--notes|--field=FIELD} [--color=auto|never|always] {NAME|UNIQUEID}
lpass *generate* [--sync=auto|now|no] [--clip, -c] [--username=USERNAME] [--url=URL] [--color=auto|never|always] {NAME|UNIQUEID} LENGTH
lpass *generate* [--sync=auto|now|no] [--clip, -c] [--username=USERNAME] [--url=URL] [--no-symbols] [--color=auto|never|always] {NAME|UNIQUEID} LENGTH
lpass *duplicate* [--sync=auto|now|no] [--color=auto|never|always] {UNIQUENAME|UNIQUEID}
lpass *rm* [--sync=auto|now|no] [--color=auto|never|always] {UNIQUENAME|UNIQUEID}
lpass *status* [--quiet, -q] [--color=auto|never|always]
Expand Down