From bfa41311eae20b92f69066aa883f654bc5593608 Mon Sep 17 00:00:00 2001 From: Rick Cogley Date: Sun, 23 Apr 2023 20:45:56 +0900 Subject: [PATCH] Enhance by getting length of symbol string (#458) The get-random-symbol function had a hard coded upper limit when using "random integer". Switch to getting the length of the symbol string automatically, so user does not have to physically count --- misc/password_generator/nupass.nu | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/misc/password_generator/nupass.nu b/misc/password_generator/nupass.nu index ce2c631..331f50b 100755 --- a/misc/password_generator/nupass.nu +++ b/misc/password_generator/nupass.nu @@ -4,6 +4,7 @@ # Updates: 20230415 - initial version # 20230416 - added @amtoine's slick probabilistic "random decimal" char capitalization # 20230417 - added script duration output in debug block +# 20230421 - added length of symbol chars to get-random-symbol function #======= NUPASS PASSWORD GENERATOR ======= # Generate password of 3 dictionary file words, numbers and symbols @@ -27,11 +28,13 @@ export def main [ let randword3 = ($dictfile | get-random-word $word_length $num_lines | random-format-word) # Get some symbols to sprinkle like salt bae - let symbol_chars = "!@#$%^&*()_-+[]" - let symb1 = (get-random-symbol $symbol_chars) - let symb2 = (get-random-symbol $symbol_chars) - let symb3 = (get-random-symbol $symbol_chars) - let symb4 = (get-random-symbol $symbol_chars) + # Update symbol chars as needed + let symbol_chars = "!@#$%^&()_-+[]{}" + let symbol_chars_len = ($symbol_chars | str length) + let symb1 = (get-random-symbol $symbol_chars $symbol_chars_len) + let symb2 = (get-random-symbol $symbol_chars $symbol_chars_len) + let symb3 = (get-random-symbol $symbol_chars $symbol_chars_len) + let symb4 = (get-random-symbol $symbol_chars $symbol_chars_len) # Print some vars if debug flag is set if $debug { @@ -85,8 +88,9 @@ def random-format-word [] { # Function to get random symbol from list of symbols def get-random-symbol [ symbolchars: string + symbolcharslen: int ] { $symbolchars | split chars - | get (random integer 0..14) + | get (random integer 0..($symbolcharslen - 1)) }