Module: Wristband::Support
- Defined in:
- lib/wristband/support.rb
Constant Summary collapse
- CONSONANTS =
%w( b c d f g h j k l m n p qu r s t v w x z ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr )
- VOWELS =
%w( a e i o u y )
Class Method Summary collapse
- .encrypt_with_salt(password, salt) ⇒ Object
- .random_salt(length = nil) ⇒ Object
- .random_string(length = 8) ⇒ Object
Class Method Details
.encrypt_with_salt(password, salt) ⇒ Object
13 14 15 16 17 |
# File 'lib/wristband/support.rb', line 13 def encrypt_with_salt(password, salt) return password unless (salt and !salt.empty?) Digest::SHA1.hexdigest([ password, salt ].join) end |
.random_salt(length = nil) ⇒ Object
20 21 22 23 24 |
# File 'lib/wristband/support.rb', line 20 def random_salt(length = nil) salt = Digest::SHA1.hexdigest([ rand, rand, random_string(64), rand, rand ].join) length ? salt[0, length] : salt end |
.random_string(length = 8) ⇒ Object
6 7 8 9 10 |
# File 'lib/wristband/support.rb', line 6 def random_string(length = 8) (1 .. length).collect { |n| (n % 2 != 0) ? CONSONANTS[rand(CONSONANTS.size)] : VOWELS[rand(VOWELS.size)] }.to_s[0, length] end |