Export Locko to 1Password

I recently changed password managers going from Locko, created by Binary Nights to 1Password from Agile Bits. Most password managers offer an Export/Import options (normally JSON being the file type of choice) however, Locko does not - and only exports its own format.

I have written a simple bit of PHP to transform the file from Locko into 1Password (or other password manager with some tweaking) compatible files.

How To: #

  1. Open Locko and go to File -> Export, choose a location for your file
  2. This will create a locko.lockexp (or similar). Change the lockexp to zip - you now have a compressed folder
  3. Extract the folder
  4. This will contain several folders with very long names - clicking through them will show some with files - open one of the files to make sure its the one with logins in
  5. Copy the below code and save it in the parent folder - update the $folder variable at the top to be the name of your folder
  6. Open up terminal, cd to the location of the file and run: $ php file.php
  7. Once completed - you should see a new csv file which you can then import into 1Password

The Code: #

<?php
    // The name of the folder where the logins are
    $folder = './FOLDER NAME/';
    // The file name you want to save as
    $title = 'Logins';
    // A csv function - from http://webtricksandtreats.com/export-to-csv-php/
    function convert_to_csv($input_array, $output_file_name, $delimiter) {
        $temp_memory = fopen('php://memory', 'w');
        foreach ($input_array as $line)
            fputcsv($temp_memory, $line, $delimiter);
        fseek($temp_memory, 0);
        file_put_contents($output_file_name, $temp_memory);
    }
    // Set up a data array with header rows with the correect fields
    $data = array();
    $data[] = array(
        'title' => 'title',
        'location' => 'location',
        'username' => 'username',
        'password' => 'password',
        'notes' => 'notes'
    );
    // Find all the .item files in the specified folder, extract the
    // required data and add it to the data array
    foreach (glob($folder . '*.item') as $filename) {
        $file = file_get_contents($filename);
        $thisData = json_decode($file);
        $data[] = array(
            'title' => $thisData->title,
            'location' => $thisData->data->fields->url,
            'username' => $thisData->data->fields->username,
            'password' => $thisData->data->fields->password,
            'notes' => $thisData->data->note
        );
    }
    echo 'Nice work - thats ' . count($data) . ' logins ready for anything!' . PHP_EOL;
    // Convert array to CSV and output
    convert_to_csv($data, $title . '.csv', ',');
Mike Street

Written by Mike Street

Mike is a front-end developer from Brighton, UK. He spends his time writing, cycling and coding. You can find Mike on Twitter.