'***************************************
Sub Panel2_Click
Dim noMe As NativeObject=Me
Dim UserTxt As String
Dim PassTxt As String
Dim SomeTxt As String
Dim dict As String
dict="nameplace"
UserTxt="user"
PassTxt="pass"
SomeTxt="xxxxxxxxxx"
' save data in dict
noMe.RunMethod("saveUsername:::::",Array(Me,UserTxt,SomeTxt,PassTxt,dict))
End Sub
Sub Panel3_Click
Dim dict As String
Dim noMe As NativeObject=Me
' get data save from dict
dict="nameplace"
noMe.RunMethod("getCredentialsForServer:::",Array(Me,"GetUserPassTxt",dict))
End Sub
Sub Panel4_Click
Dim dict As String
Dim noMe As NativeObject=Me
dict="nameplace"
' remove it
noMe.RunMethod("removeAllCredentialsForServer:::",Array(Me,"GetResult",dict))
End Sub
Sub GetUserPassTxt(user As String, pass As String)
Log(user & pass)
End Sub
Sub GetResult(Result As String)
Log(Result )
End Sub
'*************************************
#If OBJC
#import "Security/Security.h"
-(void) saveUsername :(NSObject*)Trget :(NSString*)user :(NSString*)SomeTxt :(NSString*)pass :(NSString*)server {
// Create dictionary of search parameters
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, server, kSecAttrServer, kCFBooleanTrue, kSecReturnAttributes, nil];
// Remove any old values from the keychain
OSStatus err = SecItemDelete((__bridge CFDictionaryRef) dict);
// Create dictionary of parameters to add
NSData* passwordData = [pass dataUsingEncoding:NSUTF8StringEncoding];
// dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, server, kSecAttrServer, passwordData, kSecValueData, user, kSecAttrAccount, nil];
dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, server, kSecAttrServer, passwordData, kSecValueData, user, kSecAttrAccount , SomeTxt, kSecAttrAccount, nil];
// Try to save to keychain
err = SecItemAdd((__bridge CFDictionaryRef) dict, NULL);
}
-(void) getCredentialsForServer :(NSObject*)Trget :(NSString*)GetUserPassTxt :(NSString*)server {
// Create dictionary of search parameters
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, server, kSecAttrServer, kCFBooleanTrue, kSecReturnAttributes, kCFBooleanTrue, kSecReturnData, nil];
// Look up server in the keychain
NSDictionary* found = nil;
CFDictionaryRef foundCF;
OSStatus err = SecItemCopyMatching((__bridge CFDictionaryRef) dict, (CFTypeRef*)&foundCF);
// Check if found
found = (__bridge NSDictionary*)(foundCF);
if (!found)
return;
// Found
NSString* user = (NSString*) [found objectForKey:(__bridge id)(kSecAttrAccount)];
// NSString* SomeTxt =(NSString*) [found objectForKey:(__bridge id)(kSecAttrAccountm)];
NSString* pass = [[NSString alloc] initWithData:[found objectForKey:(__bridge id)(kSecValueData)] encoding:NSUTF8StringEncoding];
[self.__c CallSubDelayed3:self.bi :Trget :(GetUserPassTxt) :(user) :(pass) ];
}
//----------------------------------
-(void) removeAllCredentialsForServer :(NSObject*)Trget :(NSString*)GetResult :(NSString*)server {
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)(kSecClassInternetPassword), kSecClass, server, kSecAttrServer, kCFBooleanTrue, kSecReturnAttributes, kCFBooleanTrue, kSecReturnData, nil];
OSStatus err = SecItemDelete((__bridge CFDictionaryRef) dict);
[self.__c CallSubDelayed2:self.bi :Trget :(GetResult) :(@"Removeit") ];
}
#End If