Skip to content

Instantly share code, notes, and snippets.

@elliotwutingfeng
Last active April 13, 2024 15:22
Show Gist options
  • Save elliotwutingfeng/24f2669dd30853e245e5129294817f0b to your computer and use it in GitHub Desktop.
Save elliotwutingfeng/24f2669dd30853e245e5129294817f0b to your computer and use it in GitHub Desktop.
One-liner to generate alphanumeric password in Ruby (1.8.2+)
ruby -e "require 'openssl'; puts (0...24).map { c = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; i = OpenSSL::Random.random_bytes(1).unpack('C').first % c.length; c[i..i] }.join"
# Or alternatively to avoid homoglyphs (https://en.wikipedia.org/wiki/Homoglyph)
# ruby -e "require 'openssl'; puts (0...24).map { c = '3479AEFHJLNQRTYabdefghijnqrty'; i = OpenSSL::Random.random_bytes(1).unpack('C').first % c.length; c[i..i] }.join"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment