Skip to content

Commit

Permalink
Use SecureRandom
Browse files Browse the repository at this point in the history
  • Loading branch information
Williams, Joshua authored and Williams, Joshua committed Sep 25, 2019
1 parent 7b7c478 commit 5adce57
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/random_password_generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'securerandom'

module RandomPasswordGenerator
# Generates a random password
# Arguments:
Expand All @@ -20,6 +22,6 @@ def self.generate(length = 8, options = {})
# Skip characters that are unsafe for urls
chars -= %w($ & + , / : \; = ? @ < > # % { } | ^ ~ [ ] `) if options[:skip_url_unsafe]

(1..length).collect{chars[rand(chars.size)]}.join
(1..length).collect{chars[SecureRandom.random_number(chars.size)]}.join
end
end

0 comments on commit 5adce57

Please sign in to comment.