summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-08-06 00:59:39 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-08-06 00:59:39 +0200
commit15e5e9c2be935215de143cb39beae9237fa0044e (patch)
treeb8b5fb6cd809e9c9f8113256fa9c624fd1f9c3ae
parenta68e06fefc0d53cadbf09fde95f1d49bfb74ee06 (diff)
downloadayk-15e5e9c2be935215de143cb39beae9237fa0044e.zip
ayk-15e5e9c2be935215de143cb39beae9237fa0044e.tar.gz
JCryption::digest gets trickier
-rw-r--r--lib/ayk/jcryption.rb10
1 files changed, 3 insertions, 7 deletions
diff --git a/lib/ayk/jcryption.rb b/lib/ayk/jcryption.rb
index d498184..a95cadc 100644
--- a/lib/ayk/jcryption.rb
+++ b/lib/ayk/jcryption.rb
@@ -54,13 +54,9 @@ module JCryption
n = passwd.length
i = ((n/2)+1)-n%8
i=0 if i<0
- if salt.nil?
- m = Digest::MD5.new
- m << Time.now.to_s
- n = Time.now.to_i%20
- salt = m.to_s[n..n+12]
- end
- d = Digest::SHA2.new << passwd[0..i]+salt+passwd[i+1..-1]
+ j = n%20
+ salt = Digest::MD5.new << Time.now.to_s if salt.nil?
+ d = Digest::SHA2.new << passwd[0..i]+salt.to_s[j..j+12]+passwd[i+1..-1]
[d,salt]
end
module_function :digest