From 5bcbdc6f7031cba7c0f7fe7be9680efa7416dc84 Mon Sep 17 00:00:00 2001 From: Luke Ehresman Date: Mon, 13 Feb 2012 09:24:01 -0500 Subject: [PATCH] added random sha1 hash to simulate a password field --- lib/random.rb | 1 + lib/random_sha1_hash.rb | 7 +++++++ makefake.rb | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 lib/random_sha1_hash.rb diff --git a/lib/random.rb b/lib/random.rb index c62e192..82ae3f2 100644 --- a/lib/random.rb +++ b/lib/random.rb @@ -2,3 +2,4 @@ require File.join(File.dirname(__FILE__), 'random_us_surname.rb') require File.join(File.dirname(__FILE__), 'random_us_zip.rb') require File.join(File.dirname(__FILE__), 'random_us_city.rb') +require File.join(File.dirname(__FILE__), 'random_sha1_hash.rb') diff --git a/lib/random_sha1_hash.rb b/lib/random_sha1_hash.rb new file mode 100644 index 0000000..94c9f2d --- /dev/null +++ b/lib/random_sha1_hash.rb @@ -0,0 +1,7 @@ +require 'digest/sha1' + +class RandomSha1Hash + def random + Digest::SHA1.hexdigest "#{Time.now.to_f}#{rand}" + end +end diff --git a/makefake.rb b/makefake.rb index 5769a63..9c1ee8d 100755 --- a/makefake.rb +++ b/makefake.rb @@ -13,13 +13,14 @@ opts.on("--records n", Integer, "Number of records to generate", '=MANDATORY') { |n| options[:count] = n } - opts.on("--fields x,y,z", Array, "Random fields to include", "Fields can be: city, zip, surname, firstname") do |fields| + opts.on("--fields x,y,z", Array, "Random fields to include", "Fields can be: city, zip, surname, firstname, sha1hash") do |fields| fields.each do |field| case field when 'city' then options[:fields].push(RandomUSCity.new US_GEOGRAPHY) when 'zip' then options[:fields].push(RandomUSZip.new US_GEOGRAPHY) when 'surname' then options[:fields].push(RandomUSSurname.new US_SURNAMES) when 'firstname' then options[:fields].push(RandomUSFirstname.new US_FIRSTNAMES) + when 'sha1hash' then options[:fields].push(RandomSha1Hash.new) else puts "Invalid field #{field}" puts opts