KeychainItem

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from Object)


Refers to a macOS Keychain item.


Properties
AccountName Description Label
Comment Handle fa-lock-32.png ServiceName


Methods
Remove


Notes

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

Examples

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

See Also

Keychain class; KeychainException error; System module.