Module: SGPass
- Defined in:
- lib/sgpass.rb,
lib/sgpass/version.rb
Overview
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.generate(password, domain, options = {}) ⇒ Object
Generates a password.
-
.get_top_domain(uri, enable_tld = true) ⇒ Object
Returns the domain.
- .version ⇒ Object
Class Method Details
.generate(password, domain, options = {}) ⇒ Object
Generates a password.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sgpass.rb', line 18 def self.generate(password, domain, ={}) length = ([:length] || 10).to_i domain = get_top_domain(domain, !([:tld] == false)) str = "#{password}:#{domain}" i = 0 while i < 10 || !strong_enough?(str[0...length]) str = b64_md5(str) i += 1 end str[0...length] end |
.get_top_domain(uri, enable_tld = true) ⇒ Object
Returns the domain
Examples
"http://admin.site.com/home.html" => "site.com"
"http://admin.site.com/home.html", false => "admin.site.com"
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sgpass.rb', line 39 def self.get_top_domain(uri, enable_tld=true) hostname = get_hostname(uri.downcase) parts = get_host_parts(hostname) if parts.size <= 2 || !enable_tld hostname else uri = parts[-2..-1].join('.') uri = "#{parts[-3]}.#{uri}" if TLD_LIST.include?(uri) uri end end |
.version ⇒ Object
4 5 6 |
# File 'lib/sgpass/version.rb', line 4 def self.version VERSION end |