From bcee0706350fdaf99ee8c9b96aa4ff86bf5c59f6 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 21 Aug 2014 08:46:22 +0200 Subject: ensure that we always select a charset --- lib/trocla/util.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/trocla/util.rb b/lib/trocla/util.rb index 78462f5..8e94d0d 100644 --- a/lib/trocla/util.rb +++ b/lib/trocla/util.rb @@ -3,12 +3,14 @@ class Trocla class Util class << self def random_str(length=12, charset='default') - _charsets = charsets[charset] + _charsets = charsets[charset] || charsets['default'] + _charsets_size = _charsets_size (1..length).collect{|a| _charsets[SecureRandom.random_number(_charsets.size)] }.join.to_s end def salt(length=8) - (1..length).collect{|a| alphanumeric[SecureRandom.random_number(alphanumeric.size)] }.join.to_s + alphanumeric_size = alphanumeric.size + (1..length).collect{|a| alphanumeric[SecureRandom.random_number(alphanumeric_size)] }.join.to_s end private -- cgit v1.2.3