Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Bhavesh Kakwani
    @bhavesh-k
    Hi Martin @MaKleSoft
    I'm trying to implement the KeePass import functions into padlock
    (I am very sorry for starting this so late, I was too busy with my final university year. But now I am free and started coding!)
    I have some trouble because I'm not very good with javascript, and I'm not even sure how to test my code
    Here are the functions I wrote so far in the import.js module:
    ' function isKeePassXML(xmldata) {
    return xmldata.split("\n")[0] == "<!DOCTYPE KEEPASSX_DATABASE>";
    }'
    that one is simple, it checks the first line of the XML file to see if it is a Keepassx database
    The function below tries to import that XML file:
    Bhavesh Kakwani
    @bhavesh-k

    '''
    function importKeePassXML(collection, xmldata) {

        // initialize list of all records in this XML file
        var records = "Name,Category,Username,Password,URL,Notes\n";
    
        // get all the "groups" (aka categories) and loop through them
        var groups = xmldata.getElementsByTagName("group");
        for (group = 0; group < groups.length; group++) {
            var title = groups[group].getElementsByTagName("title");
            var category = title[0].nodeValue;
    
            // get all the entries (records) of this category and loop through them
            var entries = groups[group].getElementsByTagName("entry");
            for (entry = 0; entry < entries.length; entry++) {
                var name = entries[entry].getElementsByTagName("title").nodeValue;
                var username = entries[entry].getElementsByTagName("username").nodeValue;
                var password = entries[entry].getElementsByTagName("password").nodeValue;
                var url = entries[entry].getElementsByTagName("url").nodeValue;
                var notes = entries[entry].getElementsByTagName("comment").nodeValue;
    
                // create a record from the above info and add to records
                var record = name + "," + category + "," + username + "," + password + "," + url + "," + notes + "\n";
                records += record;
            }
        }
    
        collection.add(records);
        return records;
    }

    '''

    Sorry let me put the first function in neat code format too:
    This message was deleted
    This message was deleted
    '''
    function isKeePassXML(xmldata) {
    return xmldata.split("\n")[0] == "<!DOCTYPE KEEPASSX_DATABASE>";
    }
    '''