Skip to content

Instantly share code, notes, and snippets.

Created June 13, 2010 19:57
  • Star 18 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jmazzi/436947 to your computer and use it in GitHub Desktop.
Convert LastPass CSV to KeePassX XML
# I recommend using Pocket to do the export. It works better than the browser extensions.
require 'rubygems'
require 'htmlentities'
require 'csv'
input_file = '/path/to/passwords.csv'
output_file = File.join(`pwd`.chomp, 'pass.xml')
coder =
csv = CSV::parse( {|f|} )
passwords = {}
csv.each do |record|
passwords[coder.encode(record[5])] ||= []
passwords[coder.encode(record[5])] << { :username => coder.encode(record[1]),
:password => coder.encode(record[2]),
:title => coder.encode(record[4]),
:comment => coder.encode(record[3]),
:url => coder.encode(record[0]) }
end, 'w') do |f|
f.puts '<database>'
passwords.keys.each do |key|
f.puts ' <group>'
f.puts " <title>#{key}</title>"
passwords[key].each do |password|
f.puts " <entry>"
f.puts " <title>#{password[:title]}</title>"
f.puts " <username>#{password[:username]}</username>"
f.puts " <password>#{password[:password]}</password>"
f.puts " <url>#{password[:url]}</url>"
f.puts " <comment>#{password[:comment]}</comment>"
f.puts " </entry>"
f.puts ' </group>'
f.puts '</database>'
Copy link

tooor commented Apr 20, 2015

Thanks! This worked like a charm. Add command line arguments and they ought to add this as a plugin or something on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment