Class: Dash::Password
- Inherits:
-
Object
- Object
- Dash::Password
- Defined in:
- lib/dash/password.rb
Constant Summary collapse
- STRONG =
'ABCDEFGHJKLMNPQRSTUVWabcdefghijkmnopqrstuvw0123456789+/-_*()[]{}'
- WEAK =
'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
- LENGTH =
12
Class Method Summary collapse
- .encode(s, c) ⇒ Object
- .encrypt(key) ⇒ Object
- .generate(domain, password, weak = false, length = LENGTH) ⇒ Object
Class Method Details
.encode(s, c) ⇒ Object
17 18 19 |
# File 'lib/dash/password.rb', line 17 def self.encode(s,c) (t=s.unpack('C*').inject([0,'',0]){|a,v|a[0]==0?[2,a[1]+c[v>>2,1],v*16&48]:a[0]==2?[4,a[1]+c[v>>4|a[2],1],v*4&60]:[0,a[1]+c[v>>6|a[2],1]+c[v&63,1],0]})[1]+(t[0]==0?'':t[0]==2?c[t[2],1]+'==':c[t[2],1]+'=') end |
.encrypt(key) ⇒ Object
21 22 23 |
# File 'lib/dash/password.rb', line 21 def self.encrypt(key) Digest::SHA2.new(256).hexdigest(key || '') end |
.generate(domain, password, weak = false, length = LENGTH) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/dash/password.rb', line 9 def self.generate(domain, password, weak = false, length = LENGTH) key = encrypt password hash = encrypt "#{key}#{domain}" charset = (weak == true) ? WEAK : STRONG return encode(hash, charset)[0,length] end |