From Xojo Documentation

Revision as of 18:55, 19 November 2009 by WikiSysop (talk) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Refers to a Macintosh Keychain item.

Super Class



Name Type Description
AccountName String Contains the name of the account (required for adding, can be Nil to find).
Comment String End user editable string containing comments for this Keychain item.
Description String End-user visible string describing this Keychain item.
Integer Contains the KeyChainItem reference, for use with Macintosh toolbox calls.
Label String End-user editable string containing the label for this Keychain item.
ServiceName String Contains the name of the service (required for adding, can be Nil to find).

To add a password for an application, set ServiceName to the application's name.


Name Parameters Description
Introduced 5.2
Deletes the KeyChainItem.

You can change passwords in a KeyChain by deleting the original item using this method and adding another item.


REALbasic KeyChainItems can access passwords for applications only, not internet passwords.


The following example adds a KeyChainItem for an application and assigns a password:

Dim NewItem as KeyChainItem
  If System.KeyChainCount > 0 then
   NewItem = New KeyChainItem
   'Indicate the name of the application
   NewItem.ServiceName = "MyApplication"
   'Create a new keychain item for the application and assign the password
    System.KeyChain.AddPassword NewItem, "SecretPassword"
    MsgBox "You don't have a key chain."
  End if

  MsgBox "Can't add item: " + err.Message

The following example retrieves the password that was set in the previous example and displays it in a message box.

Dim ItemToFind as KeyChainItem
Dim password As String
ItemToFind = New KeyChainItem
'Indicate the name of the application whose keychain item you wish to find
ItemToFind.ServiceName = "MyApplication"
  'get application's password from the system keychain
password = System.KeyChain.FindPassword(ItemToFind)
MsgBox "The password for this item is: " + password
MsgBox "Can't find item: " + err.Message

See Also

KeyChain class; KeyChainException error; System module.