Class

KeychainItem


Description

Refers to a macOS Keychain item.

Methods

Name

Parameters

Returns

Shared

Remove

Property descriptions


KeychainItem.AccountName

AccountName As String

Contains the name of the account (required for adding, can be Nil to find).

This example sets the value of the AccountName field in a TextField on the form.

Var kc As Keychain
Var kci As KeychainItem

kc = New Keychain(Listbox1.SelectedRowIndex)

If kc <> Nil Then
  kci = New KeychainItem
  kci.ServiceName = SearchField.Text

  PasswordField.Text = kc.FindPassword(kci)

  ServiceNameField.Text = kci.ServiceName
  AccountNameField.Text = kci.AccountName
  CommentField.Text = kci.Comment
  LabelField.Text = kci.Label
End If

KeychainItem.Comment

Comment As String

End user editable string containing comments for this Keychain item.

This example sets the contents of the comment field in a TextField on the input form.

Var kc As Keychain
Var kci As KeychainItem

kc = New Keychain(Listbox1.SelectedRowIndex)

If kc <> Nil Then
  kci = New KeychainItem
  kci.ServiceName = SearchField.Text

  PasswordField.Text = kc.FindPassword(kci)

  ServiceNameField.Text = kci.ServiceName
  AccountNameField.Text = kci.AccountName
  CommentField.Text = kci.Comment
  LabelField.Text = kci.Label
End If

KeychainItem.Description

Description As String

End-user visible string describing this Keychain item.

This example sets the value of the Description field on a form.

Var kc As Keychain
Var kci As KeychainItem

kc = New Keychain(Listbox1.SelectedRowIndex)

If kc <> Nil Then
  kci = New KeychainItem
  kci.ServiceName = SearchField.Text

  PasswordField.Text = kc.FindPassword(kci)

  ServiceNameField.Text = kci.ServiceName
  AccountNameField.Text = kci.AccountName
  CommentField.Text = kci.Comment
  DescriptionField.Text = kci.Description
End If

KeychainItem.Handle

Handle As Integer

Contains the KeychainItem reference, for use with macOS API calls.

This property is read-only.

This example gets the handle to the KeychainItem.

Var i As Integer
Var kci As New KeychainItem
i = kci.Handle

KeychainItem.Label

Label As String

End-user editable string containing the label for this Keychain item.

This example sets the text in a TextField to the value of the Label property.

Dim kc As Keychain
Dim kci As KeychainItem

kc = New Keychain(Listbox1.SelectedRowIndex)

If kc <> Nil Then
  kci = New KeychainItem
  kci.ServiceName = SearchField.Text

  PasswordField.Text = kc.FindPassword(kci)

  ServiceNameField.Text = kci.ServiceName
  AccountNameField.Text = kci.AccountName
  CommentField.Text = kci.Comment
  LabelField.Text = kci.Label
End If

KeychainItem.ServiceName

ServiceName As 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.

This example set the text of a TextField to the description of a KeychainItem.

Var kc As Keychain
Var kci As KeychainItem

kc = New Keychain(Listbox1.SelectedRowIndex)

If kc <> Nil Then
  kci = New KeychainItem
  kci.ServiceName = SearchField.Text

  PasswordField.Text = kc.FindPassword(kci)

  ServiceNameField.Text = kci.ServiceName
  AccountNameField.Text = kci.AccountName
  CommentField.Text = kci.Comment
  LabelField.Text = kci.Label
End If

Method descriptions


KeychainItem.Remove

Remove

Removes the KeychainItem.

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

This example removes the current KeychainItem stored in the variable kci.

kci.Remove

Notes

KeychainItems can access passwords for applications only, not internet passwords.

Sample code

The following example adds a KeychainItem for an application and assigns a password.

Var newItem As KeychainItem
If System.KeychainCount > 0 Then
  newItem = New KeychainItem
  ' Indicate the name of the application
  newItem.ServiceName = "MyApplication"

  Try
    ' Create a new keychain item for the application and assign the password
    System.Keychain.AddPassword(newItem, "SecretPassword")
  Catch Exception error As KeychainException
    MessageBox("Can't add item: " + error.Message)
  End Try
Else
  MessageBox("You don't have a key chain.")
End If

The following example retrieves the password and displays it in a message box.

Var itemToFind As KeychainItem
Var password As String

itemToFind = New KeychainItem
' Indicate the name of the application whose keychain item you wish to find
itemToFind.ServiceName = "MyApplication"

Try
  ' get application's password from the system keychain
  password = System.Keychain.FindPassword(itemToFind)
  MessageBox("The password for this item is: " + password)
Catch Exception error As KeychainException
  MessageBox("Can't find item: " + error.Message)
End Try

Compatibility

All project types on all supported operating systems.

See also

Object parent class; Keychain class; KeychainException error; System module.