Difference between revisions of "KeychainItem"
From Xojo Documentation
m (1 revision) |
|||
(21 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{ClassBox | ||
+ | | super=[[Object]] | ||
+ | | platform=mac | ||
+ | | scope=global | ||
+ | }} | ||
+ | {{Description | ||
+ | |text = Refers to a macOS [[Keychain|Keychain]] item. }} | ||
− | |||
− | |||
+ | <dynamicTable id="Properties" class="propertyTable" title="Properties" columns="3"> | ||
+ | {{Property | name=AccountName | type=String | platform=all | description=( String) Contains the name of the account (required for adding, can be Nil to find). }} | ||
+ | {{Property | name=Comment | type=String | platform=all | description=( String) End user editable string containing comments for this Keychain item. }} | ||
+ | {{Property | name=Description | type=String | platform=all | description=( String) End-user visible string describing this Keychain item. }} | ||
+ | {{Property | name=Handle | type=Integer | platform=all | readonly=yes | description=( Integer) Contains the KeychainItem reference, for use with Macintosh toolbox calls. }} | ||
+ | {{Property | name=Label | type=String | platform=all | description=( String) End-user editable string containing the label for this Keychain item. }} | ||
+ | {{Property | name=ServiceName | type=String | platform=all | description=( String) Contains the name of the service (required for adding, can be Nil to find). }} | ||
+ | </dynamicTable> | ||
− | == | + | <dynamicTable id="Methods" class="methodTable" title="Methods" columns="2"> |
− | + | {{Method | name=Remove | description=Remove()
Removes the KeychainItem. }} | |
+ | </dynamicTable> | ||
− | |||
− | + | ==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. | ||
− | + | <rbcode> | |
+ | 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 | ||
+ | </rbcode> | ||
− | + | The following example retrieves the password and displays it in a message box. | |
− | |||
− | + | <rbcode> | |
− | + | 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 | ||
+ | </rbcode> | ||
− | + | ==See Also== | |
− | + | [[Keychain]] class; [[KeychainException]] error; [[System]] module. | |
− | + | [[Category:Language_Classes]] | |
− | + | [[Category:Macintosh_Keychains]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | [[Category: | ||
− | [[Category: |
Latest revision as of 23:27, 29 August 2019
Class (inherits from Object)
![]() |
This class is only available on the macOS platform. For cross-platform compatibility, use #If...#Endif with the Target... specifiers to make sure you will not attempt to use this class on an incompatible platform. |
Refers to a macOS Keychain item.
Properties | ||||||
|
Methods | |
|
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
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
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.