Created
December 12, 2011 23:01
-
-
Save haggen/1469554 to your computer and use it in GitHub Desktop.
Password management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'http://rubygems.org' | |
gem 'fast-aes' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -rubygems | |
require 'fast-aes' | |
key = ':9i"+;e-(b(+ZU)[' | |
aes = FastAES.new(key) | |
help = %Q( | |
Usage: #{$0} <option> <argument> | |
Options: | |
-q Query database for giving argument | |
-g Generate random key with 8 characters | |
-s Display database statistic | |
) | |
case ARGV[0] | |
when '-g' | |
puts rand(16**16).to_s(36)[0..7] | |
when '-q' | |
query = ARGV[1].split('').join('.*') | |
database = File.read('~/pw.db').split("\n") | |
matches = [] | |
database.each do |n| | |
entry = aes.decrypt(n) | |
matches << entry if entry[/#{query}/] | |
end | |
if matches.empty? | |
puts 'No matches found' | |
else | |
if matches.size == 1 | |
pick = 0 | |
else | |
matches.each_index do |i| | |
puts "#{i + 1} - #{matches[i].split(' ')[2..-1].join(' ')}" | |
end | |
puts "Which one will you pick ? [1-#{matches.size}]" | |
pick = STDIN.gets.chomp.to_i - 1 | |
end | |
system("echo #{matches[pick].split(' ')[1].strip} | tr -d '\n' | pbcopy") | |
end | |
when nil | |
puts help | |
else | |
database = File.open('~/pw.db', 'a') | |
database << aes.encrypt(ARGV.join(' ')) + "\n" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem install fast-aes | |
curl -o /usr/bin/pw https://gist.github.com/raw/1469554/5ddf9b03508d2bd33c2fca511d9ec5b5f9edb812/pw.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment