sgpass 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +26 -0
- data/bin/sgpass +38 -0
- data/lib/sgpass.rb +75 -0
- data/lib/sgpass/version.rb +7 -0
- metadata +60 -0
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# SuperGenPass for Ruby
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
Install it:
|
6
|
+
|
7
|
+
gem install sgpass
|
8
|
+
|
9
|
+
To generate a password for a site, use:
|
10
|
+
|
11
|
+
sgpass facebook.com
|
12
|
+
|
13
|
+
You may even pass full URL's and `sgpass` will figure it out:
|
14
|
+
|
15
|
+
sgpass http://www.facebook.com/profile.php
|
16
|
+
|
17
|
+
...These will prompt you for your master password. If you want to do it
|
18
|
+
straight from the command line:
|
19
|
+
|
20
|
+
sgpass facebook.com MyPassword
|
21
|
+
|
22
|
+
Or from your Ruby app, you may:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
SGPass.generate('hunter2', 'http://www.facebook.com')
|
26
|
+
```
|
data/bin/sgpass
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.expand_path('../../lib/sgpass', __FILE__)
|
3
|
+
|
4
|
+
def print_usage(options={})
|
5
|
+
full = options[:full]
|
6
|
+
cmd = options[:cmd] || File.basename($0)
|
7
|
+
|
8
|
+
$stderr.write "Usage: #{cmd} URL [PASSWORD]\n"
|
9
|
+
if full
|
10
|
+
$stderr.write "\n"
|
11
|
+
$stderr.write "Generates a site-specific password for the given URL and master password.\n"
|
12
|
+
$stderr.write "If no password is given, you will be prompted for one.\n"
|
13
|
+
$stderr.write "\n"
|
14
|
+
$stderr.write "Examples:\n"
|
15
|
+
$stderr.write " #{cmd} twitter.com\n"
|
16
|
+
$stderr.write " #{cmd} facebook.com HelloThere20\n"
|
17
|
+
$stderr.write " #{cmd} http://admin.site.com/page.html hunter2\n"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
if ARGV == ['--help'] || ARGV == ['-h'] || ARGV.empty?
|
22
|
+
print_usage :full => true
|
23
|
+
|
24
|
+
elsif ARGV.size == 1
|
25
|
+
uri, _ = ARGV
|
26
|
+
$stderr.write "Password: "
|
27
|
+
passwd = STDIN.readline.strip
|
28
|
+
|
29
|
+
puts SGPass.generate(passwd, uri)
|
30
|
+
|
31
|
+
elsif ARGV.size != 2
|
32
|
+
print_usage
|
33
|
+
exit 256
|
34
|
+
|
35
|
+
else
|
36
|
+
uri, passwd = ARGV
|
37
|
+
puts SGPass.generate(passwd, uri)
|
38
|
+
end
|
data/lib/sgpass.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
# Password generator.
|
5
|
+
#
|
6
|
+
# == Common usage
|
7
|
+
#
|
8
|
+
# SGPass.generate('password', 'facebook.com')
|
9
|
+
#
|
10
|
+
# # Specified length
|
11
|
+
# SGPass.generate('password', 'facebook.com', length: 12)
|
12
|
+
#
|
13
|
+
# # Disable subdomain retrieval
|
14
|
+
# SGPass.generate('password', 'facebook.com', tld: false)
|
15
|
+
#
|
16
|
+
module SGPass
|
17
|
+
# Generates a password.
|
18
|
+
def self.generate(password, domain, options={})
|
19
|
+
length = (options[:length] || 10).to_i
|
20
|
+
domain = get_top_domain(domain, !(options[:tld] == false))
|
21
|
+
|
22
|
+
str = "#{password}:#{domain}"
|
23
|
+
|
24
|
+
i = 0
|
25
|
+
while i < 10 || !strong_enough?(str[0...length])
|
26
|
+
str = b64_md5(str)
|
27
|
+
i += 1
|
28
|
+
end
|
29
|
+
|
30
|
+
str[0...length]
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns the domain
|
34
|
+
#
|
35
|
+
# == Examples
|
36
|
+
# "http://admin.site.com/home.html" => "site.com"
|
37
|
+
# "http://admin.site.com/home.html", false => "admin.site.com"
|
38
|
+
#
|
39
|
+
def self.get_top_domain(uri, enable_tld=true)
|
40
|
+
hostname = get_hostname(uri.downcase)
|
41
|
+
parts = get_host_parts(hostname)
|
42
|
+
|
43
|
+
if parts.size <= 2 || !enable_tld
|
44
|
+
hostname
|
45
|
+
else
|
46
|
+
uri = parts[-2..-1].join('.')
|
47
|
+
uri = "#{parts[-3]}.#{uri}" if TLD_LIST.include?(uri)
|
48
|
+
uri
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def self.strong_enough?(str)
|
54
|
+
str.match(/^[a-z]/) && str.match(/[0-9]/) && str.match(/[A-Z]/)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.b64_md5(str)
|
58
|
+
Digest::MD5.base64digest(str).tr('=+/', 'A98')
|
59
|
+
end
|
60
|
+
|
61
|
+
# "facebook.com" => ["facebook", "com"]
|
62
|
+
def self.get_host_parts(host)
|
63
|
+
host.match(IP_MATCH) ? [host] : host.split('.')
|
64
|
+
end
|
65
|
+
|
66
|
+
# "http://www.facebook.com/home.php" => "www.facebook.com"
|
67
|
+
def self.get_hostname(uri)
|
68
|
+
m = uri.match(URI_MATCH) || uri.match(/^([^\/:]+)/)
|
69
|
+
m ? m[1] : uri
|
70
|
+
end
|
71
|
+
|
72
|
+
URI_MATCH = /^(?:http|https|ftp|ftps|webdav|gopher|rtsp|irc|nntp|pop|imap|smtp):\/\/([^\/:]+)/
|
73
|
+
IP_MATCH = /^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/
|
74
|
+
TLD_LIST = %w[ac.ac com.ac edu.ac gov.ac net.ac mil.ac org.ac com.ae net.ae org.ae gov.ae ac.ae co.ae sch.ae pro.ae com.ai org.ai edu.ai gov.ai com.ar net.ar org.ar gov.ar mil.ar edu.ar int.ar co.at ac.at or.at gv.at priv.at com.au gov.au org.au edu.au id.au oz.au info.au net.au asn.au csiro.au telememo.au conf.au otc.au id.au com.az net.az org.az com.bb net.bb org.bb ac.be belgie.be dns.be fgov.be com.bh gov.bh net.bh edu.bh org.bh com.bm edu.bm gov.bm org.bm net.bm adm.br adv.br agr.br am.br arq.br art.br ato.br bio.br bmd.br cim.br cng.br cnt.br com.br coop.br ecn.br edu.br eng.br esp.br etc.br eti.br far.br fm.br fnd.br fot.br fst.br g12.br ggf.br gov.br imb.br ind.br inf.br jor.br lel.br mat.br med.br mil.br mus.br net.br nom.br not.br ntr.br odo.br org.br ppg.br pro.br psc.br psi.ov.au org.au edu.au id.au oz.au info.au net.au asn.au csiro.au telememo.au conf.au otc.au id.au com.az net.az org.az com.bb net.bb org.bb ac.be belgie.be dns.be fgov.be com.bh gov.bh net.bh edu.bh org.bh com.bm edu.bm gov.bm org.bm net. gov.cn net.cn org.cn ac.cn ah.cn bj.cn cq.cn gd.cn gs.cn gx.cn gz.cn hb.cn he.cn hi.cn hk.cn hl.cn hn.cn jl.cn js.cn ln.cn mo.cn nm.cn nx.cn qh.cn sc.cn sn.cn sh.cn sx.cn tj.cn tw.cn xj.cn xz.cn yn.cn zj.cn arts.co com.co edu.co firm.co gov.co info.co int.co nom.co mil.co org.co rec.co store.co web.co ac.cr co.cr ed.cr fi.cr go.cr or.cr sa.cr com.cu net.cu org.cu ac.cy com.cy gov.cy net.cy org.cy co.dk art.do com.do edu.do gov.do gob.do org.do mil.do net.do sld.do web.do com.dz org.dz net.dz gov.dz edu.dz ass.dz pol.dz art.dz com.ec k12.ec edu.ec fin.ec med.ec gov.ec mil.ec org.ec net.ec com.ee pri.ee fie.ee org.ee med.ee com.eg edu.eg eun.eg gov.eg net.eg org.eg sci.eg com.er net.er org.er edu.er mil.er gov.er ind.er com.es org.es gob.es edu.es nom.es com.et gov.et org.et edu.et net.et biz.et name.et info.et ac.fj com.fj gov.fj id.fj org.fj school.fj com.fk ac.fk gov.fk net.fk nom.fk org.fk asso.fr nom.fr barreau.fr com.fr prd.fr presse.fr tm.fr aeroport.fr assedic.fr avocat.fr avoues.fr cci.fr chambagri.fr chirurgiens-dentistes.fr experts-comptables.fr geometre-expert.fr gouv.fr greta.fr huissier-justice.fr medecin.fr notaires.fr pharmacien.fr port.fr veterinaire.fr com.ge edu.ge gov.ge mil.ge net.ge org.ge pvt.ge co.gg org.gg sch.gg ac.gg gov.gg ltd.gg ind.gg net.gg alderney.gg guernsey.gg sark.gg com.gr edu.gr gov.gr net.gr org.gr com.gt edu.gt net.gt gob.gt org.gt mil.gt ind.gt com.gu edu.gu net.gu org.gu gov.gu mil.gu com.hk net.hk org.hk idv.hk gov.hk edu.hk co.hu 2000.hu erotika.hu jogasz.hu sex.hu video.hu info.hu agrar.hu film.hu konyvelo.hu shop.hu org.hu bolt.hu forum.hu lakas.hu suli.hu priv.hu casino.hu games.hu media.hu szex.hu sport.hu city.hu hotel.hu news.hu tozsde.hu tm.hu erotica.hu ingatlan.hu reklam.hu utazas.hu ac.id co.id go.id mil.id net.id or.id co.il net.il org.il ac.il gov.il k12.il muni.il idf.il co.im net.im org.im ac.im lkd.co.im gov.im nic.im plc.co.im co.in net.in ac.in ernet.in gov.in nic.in res.in gen.in firm.in mil.in org.in ind.in ac.ir co.ir gov.ir id.ir net.ir org.ir sch.ir ac.je co.je net.je org.je gov.je ind.je jersey.je ltd.je sch.je com.jo org.jo net.jo gov.jo edu.jo mil.jo ad.jp ac.jp co.jp go.jp or.jp ne.jp gr.jp ed.jp lg.jp net.jp org.jp gov.jp hokkaido.jp aomori.jp iwate.jp miyagi.jp akita.jp yamagata.jp fukushima.jp ibaraki.jp tochigi.jp gunma.jp saitama.jp chiba.jp tokyo.jp kanagawa.jp niigata.jp toyama.jp ishikawa.jp fukui.jp yamanashi.jp nagano.jp gifu.jp shizuoka.jp aichi.jp mie.jp shiga.jp kyoto.jp osaka.jp hyogo.jp nara.jp wakayama.jp tottori.jp shimane.jp okayama.jp hiroshima.jp yamaguchi.jp tokushima.jp kagawa.jp ehime.jp kochi.jp fukuoka.jp saga.jp nagasaki.jp kumamoto.jp oita.jp miyazaki.jp kagoshima.jp okinawa.jp sapporo.jp sendai.jp yokohama.jp kawasaki.jp nagoya.jp kobe.jp kitakyushu.jp utsunomiya.jp kanazawa.jp takamatsu.jp matsuyama.jp com.kh net.kh org.kh per.kh edu.kh gov.kh mil.kh ac.kr co.kr go.kr ne.kr or.kr pe.kr re.kr seoul.kr kyonggi.kr com.kw net.kw org.kw edu.kw gov.kw com.la net.la org.la com.lb org.lb net.lb edu.lb gov.lb mil.lb com.lc edu.lc gov.lc net.lc org.lc com.lv net.lv org.lv edu.lv gov.lv mil.lv id.lv asn.lv conf.lv com.ly net.ly org.ly co.ma net.ma org.ma press.ma ac.ma com.mk com.mm net.mm org.mm edu.mm gov.mm com.mn org.mn edu.mn gov.mn museum.mn com.mo net.mo org.mo edu.mo gov.mo com.mt net.mt org.mt edu.mt tm.mt uu.mt com.mx net.mx org.mx gob.mx edu.mx com.my org.my gov.my edu.my net.my com.na org.na net.na alt.na edu.na cul.na unam.na telecom.na com.nc net.nc org.nc ac.ng edu.ng sch.ng com.ng gov.ng org.ng net.ng gob.ni com.ni net.ni edu.ni nom.ni org.ni com.np net.np org.np gov.np edu.np ac.nz co.nz cri.nz gen.nz geek.nz govt.nz iwi.nz maori.nz mil.nz net.nz org.nz school.nz com.om co.om edu.om ac.om gov.om net.om org.om mod.om museum.om biz.om pro.om med.om com.pa net.pa org.pa edu.pa ac.pa gob.pa sld.pa edu.pe gob.pe nom.pe mil.pe org.pe com.pe net.pe com.pg net.pg ac.pg com.ph net.ph org.ph mil.ph ngo.ph aid.pl agro.pl atm.pl auto.pl biz.pl com.pl edu.pl gmina.pl gsm.pl info.pl mail.pl miasta.pl media.pl mil.pl net.pl nieruchomosci.pl nom.pl org.pl pc.pl powiat.pl priv.pl realestate.pl rel.pl sex.pl shop.pl sklep.pl sos.pl szkola.pl targi.pl tm.pl tourism.pl travel.pl turystyka.pl com.pk net.pk edu.pk org.pk fam.pk biz.pk web.pk gov.pk gob.pk gok.pk gon.pk gop.pk gos.pk edu.ps gov.ps plo.ps sec.ps com.pt edu.pt gov.pt int.pt net.pt nome.pt org.pt publ.pt com.py net.py org.py edu.py com.qa net.qa org.qa edu.qa gov.qa asso.re com.re nom.re com.ro org.ro tm.ro nt.ro nom.ro info.ro rec.ro arts.ro firm.ro store.ro www.ro com.ru net.ru org.ru gov.ru pp.ru com.sa edu.sa sch.sa med.sa gov.sa net.sa org.sa pub.sa com.sb net.sb org.sb edu.sb gov.sb com.sd net.sd org.sd edu.sd sch.sd med.sd gov.sd tm.se press.se parti.se brand.se fh.se fhsk.se fhv.se komforb.se kommunalforbund.se komvux.se lanarb.se lanbib.se naturbruksgymn.se sshn.se org.se pp.se com.sg net.sg org.sg edu.sg gov.sg per.sg com.sh net.sh org.sh edu.sh gov.sh mil.sh gov.st saotome.st principe.st consulado.st embaixada.st org.st edu.st net.st com.st store.st mil.st co.st com.sv org.sv edu.sv gob.sv red.sv com.sy net.sy org.sy gov.sy ac.th co.th go.th net.th or.th com.tn net.tn org.tn edunet.tn gov.tn ens.tn fin.tn nat.tn ind.tn info.tn intl.tn rnrt.tn rnu.tn rns.tn tourism.tn com.tr net.tr org.tr edu.tr gov.tr mil.tr bbs.tr k12.tr gen.tr co.tt com.tt org.tt net.tt biz.tt info.tt pro.tt int.tt coop.tt jobs.tt mobi.tt travel.tt museum.tt aero.tt name.tt gov.tt edu.tt nic.tt us.tt uk.tt ca.tt eu.tt es.tt fr.tt it.tt se.tt dk.tt be.tt de.tt at.tt au.tt co.tv com.tw net.tw org.tw edu.tw idv.tw gov.tw com.ua net.ua org.ua edu.ua gov.ua ac.ug co.ug or.ug go.ug co.uk me.uk org.uk edu.uk ltd.uk plc.uk net.uk sch.uk nic.uk ac.uk gov.uk nhs.uk police.uk mod.uk dni.us fed.us com.uy edu.uy net.uy org.uy gub.uy mil.uy com.ve net.ve org.ve co.ve edu.ve gov.ve mil.ve arts.ve bib.ve firm.ve info.ve int.ve nom.ve rec.ve store.ve tec.ve web.ve co.vi net.vi org.vi com.vn biz.vn edu.vn gov.vn net.vn org.vn int.vn ac.vn pro.vn info.vn health.vn name.vn com.vu edu.vu net.vu org.vu de.vu ch.vu fr.vu com.ws net.ws org.ws gov.ws edu.ws ac.yu co.yu edu.yu org.yu com.ye net.ye org.ye gov.ye edu.ye mil.ye ac.za alt.za bourse.za city.za co.za edu.za gov.za law.za mil.za net.za ngo.za nom.za org.za school.za tm.za web.za co.zw ac.zw org.zw gov.zw eu.org au.com br.com cn.com de.com de.net eu.com gb.com gb.net hu.com no.com qc.com ru.com sa.com se.com uk.com uk.net us.com uy.com za.com dk.org tel.no fax.nr mob.nr mobil.nr mobile.nr tel.nr tlf.nr e164.arpa]
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sgpass
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rico Sta. Cruz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-10 00:00:00 +08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: SGPass uses a hash algorithm to transform a master password into unique, complex passwords for the Web sites you visit. This is a Ruby port of www.supergenpass.com.
|
18
|
+
email:
|
19
|
+
- rico@sinefunc.com
|
20
|
+
executables:
|
21
|
+
- sgpass
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- lib/sgpass/version.rb
|
28
|
+
- lib/sgpass.rb
|
29
|
+
- bin/sgpass
|
30
|
+
- README.md
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/rstacruz/sgpass
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.6.2
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Password generator based on hash algorithms.
|
59
|
+
test_files: []
|
60
|
+
|