Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacClassic/Keychain/Keychain Test 2
Function:
Required plugins for this example: MBS MacClassic Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacClassic/Keychain/Keychain Test 2
This example is the version from Tue, 21th Oct 2013.
Project "Keychain Test 2.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PbSet Inherits PushButton
ControlInstance PbSet Inherits PushButton
EventHandler Sub Action() KeychainSetPassword TfServiceName.Text, TfAccountName.Text, TfPassword.Text Self.ContentsChanged = True End EventHandler
End Control
Control TfAccountName Inherits TextField
ControlInstance TfAccountName Inherits TextField
EventHandler Sub TextChange() Self.ContentsChanged = True End EventHandler
End Control
Control TfPassword Inherits TextField
ControlInstance TfPassword Inherits TextField
EventHandler Sub TextChange() Self.ContentsChanged = True End EventHandler
End Control
Control PbDelete Inherits PushButton
ControlInstance PbDelete Inherits PushButton
EventHandler Sub Action() KeychainDeleteItem TfServiceName.Text, TfAccountName.Text Self.ContentsChanged = True End EventHandler
End Control
Control PbShow Inherits PushButton
ControlInstance PbShow Inherits PushButton
EventHandler Sub Action() TfPassword.Text = KeychainGetPassword(TfServiceName.Text, TfAccountName.Text) End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control TfServiceName Inherits TextField
ControlInstance TfServiceName Inherits TextField
EventHandler Sub TextChange() Self.ContentsChanged = True End EventHandler
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control PbQuit Inherits PushButton
ControlInstance PbQuit Inherits PushButton
EventHandler Sub Action() Quit End EventHandler
End Control
EventHandler Sub ContentsChanged() if TfAccountName.Text <> "" and TfPassword.Text <> "" and TfServiceName.Text <> "" then PbSet.Enabled = True else PbSet.Enabled = False end if if KeychainItemExists(TfServiceName.Text, TfAccountName.Text) then PbDelete.Enabled = True PbShow.Enabled = True else PbDelete.Enabled = False PbShow.Enabled = False end if End EventHandler
Sub KeychainDeleteItem(aServiceName As String, aAccountName As String) Dim vItem As KeychainItemMBS Dim vKeychain As New KeychainMBS Dim vPasswordBlock As MemoryBlock vItem = KeychainManagerMBS.FindGenericPassword(vKeychain, aServiceName, aAccountName, vPasswordBlock) if vItem <> Nil then vItem.Delete end if End Sub
Function KeychainGetPassword(aServiceName As String, aAccountName As String) As String Dim vItem As KeychainItemMBS Dim vKeychain As New KeychainMBS Dim vPasswordBlock As MemoryBlock Dim vPassword As String vItem = KeychainManagerMBS.FindGenericPassword(vKeychain, aServiceName, aAccountName, vPasswordBlock) if vItem <> Nil then vPassword = DefineEncoding(vPasswordBlock, Encodings.UTF8) end if return vPassword End Function
Function KeychainItemExists(aServiceName As String, aAccountName As String) As Boolean Dim vItem As KeychainItemMBS Dim vKeychain As New KeychainMBS Dim vPasswordBlock As MemoryBlock Dim vPassword As String vItem = KeychainManagerMBS.FindGenericPassword(vKeychain, aServiceName, aAccountName, vPasswordBlock) return (vItem <> Nil) End Function
Sub KeychainSetPassword(aServiceName As String, aAccountName As String, aPassword As String) Dim vItem As KeychainItemMBS Dim vKeychain As New KeychainMBS Dim vPasswordBlock As MemoryBlock Dim vPassword As String vItem = KeychainManagerMBS.FindGenericPassword(vKeychain, aServiceName, aAccountName, vPasswordBlock) if vItem = Nil then Dim vKeyChainItem As KeychainItemMBS vKeyChainItem = vKeyChain.AddGenericPassword(aServiceName, aAccountName, aPassword) else vPassword = DefineEncoding(vPasswordBlock, Encodings.UTF8) if vPassword <> aPassword then vItem.Password = aPassword end if end if End Sub
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacClassic Plugin.




Links
MBS Xojo PDF Plugins