Top Level Namespace
Defined Under Namespace
Modules: PwdHash
Instance Method Summary collapse
- #apply_constraints(hash, size, nonalphanumeric) ⇒ Object
- #between(min, interval, offset) ⇒ Object
- #contains(result, regex) ⇒ Object
- #extract_domain(uri) ⇒ Object
- #get_hashed_password(password, realm) ⇒ Object
- #next_between(base, interval, extras) ⇒ Object
- #next_extra(extras) ⇒ Object
- #next_extra_character(extras) ⇒ Object
- #rotate(array, amount) ⇒ Object
Instance Method Details
#apply_constraints(hash, size, nonalphanumeric) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pwdhash/pwdhash.rb', line 28 def apply_constraints(hash, size, nonalphanumeric) startingSize = size - 4 # Leave room for some extra characters result = hash[0, startingSize] extras = (hash[startingSize, hash.length] || "").split('') # Add the extra characters result += (contains(result, /[A-Z]/) ? next_extra_character(extras) : next_between('A', 26, extras)) result += (contains(result, /[a-z]/) ? next_extra_character(extras) : next_between('a', 26, extras)) result += (contains(result, /[0-9]/) ? next_extra_character(extras) : next_between('0', 10, extras)) result += (contains(result, /\W/) && nonalphanumeric ? next_extra_character(extras) : '+') while (contains(result, /\W/) && !nonalphanumeric) do result = result.sub(/\W/, next_between('A', 26, extras)) end # Rotate the result to make it harder to guess the inserted locations result = result.split('') rotate(result, next_extra(extras)) return result.join('') end |
#between(min, interval, offset) ⇒ Object
15 16 17 |
# File 'lib/pwdhash/pwdhash.rb', line 15 def between(min, interval, offset) (min.ord + offset.ord % interval).chr end |
#contains(result, regex) ⇒ Object
24 25 26 |
# File 'lib/pwdhash/pwdhash.rb', line 24 def contains(result, regex) result.match(regex) end |
#extract_domain(uri) ⇒ Object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/pwdhash/extract_domain.rb', line 1 def extract_domain(uri) domains = %w( ab.ca ac.ac ac.at ac.be ac.cn ac.il ac.in ac.jp ac.kr ac.nz ac.th ac.uk ac.za adm.br adv.br agro.pl ah.cn aid.pl alt.za am.br arq.br art.br arts.ro asn.au asso.fr asso.mc atm.pl auto.pl bbs.tr bc.ca bio.br biz.pl bj.cn br.com cn.com cng.br cnt.br co.ac co.at co.il co.in co.jp co.kr co.nz co.th co.uk co.za com.au com.br com.cn com.ec com.fr com.hk com.mm com.mx com.pl com.ro com.ru com.sg com.tr com.tw cq.cn cri.nz de.com ecn.br edu.au edu.cn edu.hk edu.mm edu.mx edu.pl edu.tr edu.za eng.br ernet.in esp.br etc.br eti.br eu.com eu.lv fin.ec firm.ro fm.br fot.br fst.br g12.br gb.com gb.net gd.cn gen.nz gmina.pl go.jp go.kr go.th gob.mx gov.br gov.cn gov.ec gov.il gov.in gov.mm gov.mx gov.sg gov.tr gov.za govt.nz gs.cn gsm.pl gv.ac gv.at gx.cn gz.cn hb.cn he.cn hi.cn hk.cn hl.cn hn.cn hu.com idv.tw ind.br inf.br info.pl info.ro iwi.nz jl.cn jor.br jpn.com js.cn k12.il k12.tr lel.br ln.cn ltd.uk mail.pl maori.nz mb.ca me.uk med.br med.ec media.pl mi.th miasta.pl mil.br mil.ec mil.nz mil.pl mil.tr mil.za mo.cn muni.il nb.ca ne.jp ne.kr net.au net.br net.cn net.ec net.hk net.il net.in net.mm net.mx net.nz net.pl net.ru net.sg net.th net.tr net.tw net.za nf.ca ngo.za nm.cn nm.kr no.com nom.br nom.pl nom.ro nom.za ns.ca nt.ca nt.ro ntr.br nx.cn odo.br on.ca or.ac or.at or.jp or.kr or.th org.au org.br org.cn org.ec org.hk org.il org.mm org.mx org.nz org.pl org.ro org.ru org.sg org.tr org.tw org.uk org.za pc.pl pe.ca plc.uk ppg.br presse.fr priv.pl pro.br psc.br psi.br qc.ca qc.com qh.cn re.kr realestate.pl rec.br rec.ro rel.pl res.in ru.com sa.com sc.cn school.nz school.za se.com se.net sh.cn shop.pl sk.ca sklep.pl slg.br sn.cn sos.pl store.ro targi.pl tj.cn tm.fr tm.mc tm.pl tm.ro tm.za tmp.br tourism.pl travel.pl tur.br turystyka.pl tv.br tw.cn uk.co uk.com uk.net us.com uy.com vet.br web.za web.com www.ro xj.cn xz.cn yk.ca yn.cn za.com ) host = uri.gsub(%r(https?://), '') host = host[%r(([^/]+))] host = host.split('.') if host[2] s = host[host.length - 2] + '.' + host[host.length - 1] s = host[host.length - 3] + '.' + s if domains.include?(s) else s = host * '.' end s end |
#get_hashed_password(password, realm) ⇒ Object
76 77 78 79 |
# File 'lib/pwdhash/pwdhash.rb', line 76 def get_hashed_password(password, realm) hash = PwdHash::Hash.new(realm, password) apply_constraints(hash.hash, hash.size, hash.contains_non_alphanumeric?) end |
#next_between(base, interval, extras) ⇒ Object
19 20 21 22 |
# File 'lib/pwdhash/pwdhash.rb', line 19 def next_between(base, interval, extras) char_code = between(base[0], interval, next_extra(extras)) char_code.chr end |
#next_extra(extras) ⇒ Object
7 8 9 |
# File 'lib/pwdhash/pwdhash.rb', line 7 def next_extra(extras) extras.empty? ? 0 : extras.shift[0] end |
#next_extra_character(extras) ⇒ Object
3 4 5 |
# File 'lib/pwdhash/pwdhash.rb', line 3 def next_extra_character(extras) next_extra(extras).chr end |
#rotate(array, amount) ⇒ Object
11 12 13 |
# File 'lib/pwdhash/pwdhash.rb', line 11 def rotate(array, amount) amount.ord.downto(1) { array.push(array.shift) } end |