Sha256: 656481a1684078f772e277272c16677700e8bc7b6ed416a4d2ba0ac5bb5727fa
Contents?: true
Size: 747 Bytes
Versions: 1
Compression:
Stored size: 747 Bytes
Contents
require "zxcvbn/passgen/version" require 'zxcvbn' module Zxcvbn module Passgen class Error < StandardError; end def self.generate(length = 11) raise "Password length must be greater or equal 11." if length < 11 pass = make(length) while Zxcvbn.test(pass).score < 4 generate(length) end pass end def self.make(length) down = ('a'..'z').to_a up = ('A'..'Z').to_a digits = ('0'..'9').to_a symbols = %i[~ ! @ # $ % ^ & * ( ) + { } ? < > = ].freeze all = down + up + digits + symbols [down.sample, up.sample, digits.sample, symbols.sample] .concat((length - 4).times.map { all.sample }) .shuffle .join end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
zxcvbn-passgen-0.1.0 | lib/zxcvbn/passgen.rb |