\AlphredKeychain

Enables easy access to parts of the Keychain for secure password storage / retrieval

Uses the security command in order to add / retrieve / delete passwords. Note: we use only the "generic" password functions and not the "internet" password functions.

Summary

Methods
Properties
Constants
__construct()
save_password()
find_password()
delete_password()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
call_security()
set_service()
No private properties found
N/A

Methods

__construct()

__construct() 

Throws an exception if you try to instantiate it

Throws

\Alphred\UseOnlyAsStatic

if you try to institate a Globals object

save_password()

save_password(string  $account, string  $password, boolean  $update = true, string  $service = null) : boolean

Saves a password to the keychain

Parameters

string $account

the name of the account

string $password

the new password

boolean $update

whether or not to update an old password (defaults to true)

string $service

optional: defaults to the bundleid of the workflow (if set)

Throws

\Alphred\PasswordExists

(indirectly )when trying to add a password that already exists without specifying 'update'

Returns

boolean —

whether or not it was successful (usually true)

find_password()

find_password(string  $account, string  $service = null) : string

Retrieves a password from the keychain

Parameters

string $account

the name of an account

string $service

optional: defaults to the bundleid of the workflow (if set)

Throws

\Alphred\InvalidKeychainAccount

on an empty account

Returns

string —

the password

delete_password()

delete_password(string  $account, string  $service = null) : boolean

Deletes a password from the keychain

Parameters

string $account

the name of the account

string $service

optional: defaults to the bundleid of the workflow (if set)

Returns

boolean —

success of command

call_security()

call_security(string  $action, string  $service, string  $account, string  $args) : string|boolean

Interfaces directly with the `security` command

Parameters

string $action

one of 'add-', 'delete-', or 'find-generic-password'

string $service

the "owner" of the action; usually the bundle id

string $account

the "account" of the password

string $args

extra arguments for the security command

Throws

\Alphred\PasswordExists

when trying to add a password that already exists without specifying 'update'

\Alphred\PasswordNotFound

when trying to find a password that does not exist

\Alphred\UnknownSecurityException

when something weird happens

Returns

string|boolean —

either a found password or true

set_service()

set_service(  $service) 

Sets the service appropriately, usually to the bundle id of the workflow

Parameters

$service