PHP code example of valicek1 / keepasshttpclient

1. Go to this page and download the library: Download valicek1/keepasshttpclient library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

valicek1 / keepasshttpclient example snippets


# load key and it's id
$secret = loadKey(); // you need to implement this by yourself

# create class
# $secret[0] is 256-bit (32 characters) long key
# $secret[1] contains key id
$kpx = new KeePassHTTPClient($secret[1], $secret[0]);

# is the key associated with DB?
if (!$kpx->testAssociated()) {
	# if not, try to authorize
	$label = $kpx->authorizeKey();
	# and save key + label for next use
	saveKey($label, $secret[1]); // you need to implement this yourself
}

if ($kpx->testAssociated()) {
  // you are welcome to do something in database
  $url = "https://skype.com";
  
  // get logins
  $logins = $kpx->getLogins($url, $url); // first URL is page URL, second one is Submit url for "form"
  
  // or just their count
  $count = $kpx->getLoginsCount($url, $url)
   
  // or create new pairs in database
  $kpx->setLogin($url, $url, "username", "realPassword") 
 
}

/**
 * KeePassHTTPClient constructor.
 * @param string $key Encryption key, 256 bits
 * @param string $label Label (product of association)
 * @param string $address KeepassHTTP listening address
 * @param int    $port KeepassHTTP listening port
 */
public function __construct($key, $label = "", $address = "localhost", $port = 19455){}

public function getAddress(){} // address of server
public function getPort(){} // port of server
public function isAssociated(){} // state of last testAssociated
public function getClient(){} // return guzzle client

public function isServerListening(){} // check, if port is opened
public function sendRequest($json){} // json encode $json and send it as request. Return json object of response
public function testAssociated($empty = FALSE){} // test if key is associated or server responding (empty = TRUE)
public function authorizeKey(){} // authorize key (from constructor)
public function getLogins($url, $redirectUrl){} // find logins/passwords for entered criteria.
public function getLoginsCount($url, $redirectUrl){} // count number of items for entered criteria
public function setLogin($url, $redirectURL, $login, $password){} // save login to KeePass DB