3 ms·
I gave up on readable. with open('/dev/urandom', 'rb') as f: return base64.urlsafe_b64encode(f.read(12))
by wiredfool 4y ago
I gave up on readable.
with open('/dev/urandom', 'rb') as f:
return base64.urlsafe_b64encode(f.read(12))
- lobocinza 4y agoalias genpwd="tr -dc 'a-zA-Z0-9!@#$%*()[]{}' < /dev/urandom | fold -w 16 | head -n 1 | xclip -sel clip"
- lucb1e 4y agoI always find those annoying to copy (we use a lot of shared credentials, like when the customer gives us 3 accounts with different permission levels to pentest an application with) and it also simplifies the command to not have to specify all those symbols. You can also avoid the whole `fold` thing by just telling `head` to give you a certain number of -c instead of a certain number of -n. </dev/urandom tr -dc a-zA-Z0-9 | head -c 16 (Then again, you were proposing an alias, so then command complexity/memorability doesn't really matter.) Security level: log((26+26+10)¹⁶)/log(2) ~ 2⁹⁵ (95 bits of entropy), comparable with adding those 12 extra symbols: log((26+26+10+12)¹⁶)/log(2) ~ 2⁹⁹. (Adding a character makes more sense than adding a symbol if you want more security, all else being equal of course.) If a stupid application still has outdated password requirements (thankfully this is rare among the applications I use) then one can of course add the classic ! at the end.
- lobocinza 4y agoThey are annoying, specially when it's the wifi password and you have to enter it using a TV remote.
- lobocinza 4y agoUsing head -c 16 will show an ugly '%' at the string end when not piped.
- lucb1e 4y agoRight, I forget that it's not the default to print a \n as the first character of your PS1. Doesn't make sense to me that this isn't the default, as there are quite a few commands that might not end with a newline and then it messes up the prompt position, and it doesn't impact backwards compatibility to add it now.
- mkl 4y agoOn which OS? There it is piped, but I can't make it display a "%" any way (why would it?). I'm on Linux, using head from GNU coreutils.
- lobocinza 4y agoArch Linux. When using Zsh the last char is always a '%'. When using Bash it does no show a '%' but there's no line break. Possibly an weird interaction with my $PS1.
- mkl 4y agoThat's definitely a Zsh thing, showing that there was no newline: https://zsh.sourceforge.io/Doc/Release/Options.html#Prompting https://zsh.sourceforge.io/Doc/Release/Options.html#Promptin.... It's not to do with PS1 or PROMPT, or head.