Skip to content

Instantly share code, notes, and snippets.

@cutalion
Created October 20, 2020 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cutalion/1c5db0be3f060c311da3a979ac6a35ca to your computer and use it in GitHub Desktop.
Save cutalion/1c5db0be3f060c311da3a979ac6a35ca to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'securerandom'
LETTERS = ('a'..'z').to_a.freeze
BIG_LETTERS = ('A'..'Z').to_a.freeze
DIGITS = ('0'..'9').to_a.freeze
SPECIAL = '~`!@#$%^&*()_+{}][;:\'"/?>.<,'.split.freeze
ALL = (LETTERS + BIG_LETTERS + DIGITS + SPECIAL).freeze
length = SecureRandom.rand(43) + 8 # 8..50
at_least_one = [LETTERS.sample, BIG_LETTERS.sample, DIGITS.sample, SPECIAL.sample]
rest = (length - at_least_one.length).times.map { ALL.sample }
password = (at_least_one + rest).shuffle.join
puts password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment