Last active
August 28, 2024 20:33
-
-
Save elliotwutingfeng/24f2669dd30853e245e5129294817f0b to your computer and use it in GitHub Desktop.
One-liner to generate alphanumeric password in Ruby (1.8.2+)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby -e "require 'openssl'; c = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; puts (0...24).map { 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'; c = '3479AEFHJLNQRTYabdefghijnqrty'; puts (0...24).map { 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