67 points · by bwidlar · 7y ago · 37 comments
Then there is the side of making a password that is easy to type on a phone. Ideally, I want a hard password that doesn't require me to change input mode on my phone too many times.
Well, ideally, I'd rather I could just use my security token everywhere... But that is a separate problem.
(let ((byte (remainder (get-u8 urandom) size)))
is skewed if size isn't a power of 2. What you should do is mod by the next-largest power of 2 (e.g. if size is 82, mod by 128). Then if the result is in-range use it, otherwise discard and reroll.You need to parse the cmd, make sure you use the proper random generator, and accumulate different source of characters.
Options such as --allow-unicode, --exclude-similar-chars or --group-chars all provide small additional challenges in different areas.
It's something all students should code at least once, if not for pleasure, at least for practice.
But honestly I find it fun enough that I just wrote one again after reading the article. I'm pretty sure a timeline of all the attempts is telling of ones progression in style :)
base64 /dev/urandom | head -c 16
(Vary the number of characters according to the desired entropy: you get 6 bits of entropy for each character of output, so 16*6 = 96 bits in the example. Use /dev/random or /dev/arandom if you prefer those random sources.)For passphrases, use GNU shuf (from the coreutils package):
shuf -n 4 --random-source=/dev/urandom /usr/share/dict/wordsKeep your sanity and avoid special characters.
(it also outputs a random password if called with -r arg)
#!/bin/bash
choose() { echo ${1:RANDOM%${#1}:1} $RANDOM; }
{
choose '!@#$%^\&'
choose '0123456789'
choose 'abcdefghijklmnopqrstuvwxyz'
choose 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in $( seq 1 $(( 4 + RANDOM % 8 )) )
do
choose '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
done
} | sort -R | awk '{printf "%s",$1}'
echo ""
https://stackoverflow.com/questions/26665389/random-password...The reasoning is that `define` doesn't increate horisontal indentation.
require('uuid').v4().split('-').join('') crypto.randomBytes(16).toString('hex')>>> import uuid
>>> uuid.uuid4().hex
Interesting someone else mentioned the 14th character is always a 4... I am creeped out just a little bit (cause I never noticed).
for i in ["".join(random.choice(wordlist) for x in range(5)) for y in range(20)]:
print (i)