Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

password hash script (See related posts)

Jason's weblog post about using one password everywhere inspired this script, which generates a base-80 hash of your input string.

Feel free to replace MD5 with SHA1 or even `echo #{line} | sha -5`, to make it harder to guess which hashing mechanism was used.

Requires highline, which you can get with "gem install highline".

Warning! This does not echo your input string to the screen; when generating passwords for sites, you might want to generate it twice, to make sure you don't have any typos.

#!/usr/local/bin/ruby

require 'digest/md5'
require 'rubygems'
require 'highline/import'

CHARS = ("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a + ["!","@","#","$","%","&",
"*","-","_","=","+",":","<",">",".",",","?","~"]

line = ask("enter your string: ") {|q| q.echo = false}

n = Digest::MD5.hexdigest("#{line}").hex

pass = []

while n > 0
  pass << CHARS[n.divmod(CHARS.size)[1]]
  n = n.divmod(CHARS.size)[0]
end

puts pass.to_s


chmod 7xx it and run it, and there you go!

example:
albus:~ matt$ ./password.rb 
enter your string:  
6irO:B=5MFiOcb6Uv3ER

Comments on this post

jason posts on May 26, 2005 at 05:21
Hey hey. Fantastic.

You need to create an account or log in to post comments to this site.


Related Posts