Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Contributor: CovertBotNews - The LJ Password Generator Tool
#1
The LJ Password Generator Tool

<div data-history-node-id="1339882" class="layout layout--onecol">
<div class="layout__region layout__region--content">

<div class="field field--name-field-node-image field--type-image field--label-hidden field--item"> <img src="https://www.linuxjournal.com/sites/default/files/nodeimage/story/bigstock-login-password-12492731_1.jpg" width="500" height="333" alt="""" typeof="foaf:Image" class="img-responsive" /></div>

<div class="field field--name-node-author field--type-ds field--label-hidden field--item">by <a title="View user profile." href="https://www.linuxjournal.com/users/dave-taylor" lang="" about="https://www.linuxjournal.com/users/dave-taylor" typeof="schemaTongueerson" property="schema:name" datatype="" xml:lang="">Dave Taylor</a></div>

<div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p><em>Mnemonic passwords generally stink. A random
sequence of letters, digits and punctuation is more secure—just don't
write down your passwords, like the knucklehead antagonist does in <em>Ready
Player One</em>!</em></p>

<p>
In the password generating tool from my <a href="https://www.linuxjournal.com/content/generating-good-passwords-part-ii">last
article</a>,
at its most simple, you specify the number of characters you want in the
password, and each is then chosen randomly from a pool of acceptable values.
With the built-in <code>RANDOM</code> in the Linux shell, that's super easy to do:

</p><pre>
<code>
okay="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
okay="${okay}0123456789<>/?,>;:[{]}\|=+-_)(^%$#@!~
length=10
ltrs=${#okay}

while [ $length -ge 0 ]
do
letter="${okay:$RANDOM % $ltrs:1}"
result="$result$letter"
length=$(( $length - 1 ))
done

echo "Result: $result"
</code>
</pre>


<p>
In the actual script, I set <code>okay</code> to a single value rather than
build it in
two steps; this is just for formatting here online. Otherwise,
<code>ltrs</code> is set to
the length of <code>$okay</code> as a speedy shortcut, and the result is built up by using
the string slicing syntax of:

</p><pre>
<code>
${variable:indexlocation:length}
</code>
</pre>


<p>
To extract just the fourth character of a string, for example,
<code>${string:4:1}</code>, this
works fine and is easy. The result speaks for itself:

</p><pre>
<code>
$ sh lazy-passwords.sh
Result: Ojkr9>|}dMr
</code>
</pre>


<p>
And, a few more:

</p><pre>
<code>
Result: Mi8]TfJKVaH
Result: >MWvF2D/R?r
Result: h>J6\p4eNPH
Result: KixhCFZaesr
</code>
</pre>


<p>
Where this becomes a more complex challenge is when you decide you
don't want to have things randomly selected but instead want to weight
the results so that you have more letters than digits, or no more than a few
punctuation characters, even on a 15–20 character password.
</p>

<p>
Which is, of course, exactly what I've been building.
</p>

<p>
I have to admit that there's a certain lure to making something complex,
if nothing else than just to see if it can be done and work properly.
</p>

<h3>
Adding Weight to Letter Choices</h3>

<p>
As a result, the simple few lines above changed to this in my <a href="https://www.linuxjournal.com/content/generating-good-passwords-part-ii">last
article</a>:

</p></div>

<div class="field field--name-node-link field--type-ds field--label-hidden field--item"> <a href="https://www.linuxjournal.com/content/lj-password-generator-tool" hreflang="en">Go to Full Article</a>
</div>

</div>
</div>




https://www.linuxjournal.com/content/lj-...rator-tool
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)