Created
October 20, 2020 10:16
-
-
Save cutalion/1c5db0be3f060c311da3a979ac6a35ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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