SSKeychain 实现加载上次登录并通过
SSKeychain implementation load last login and pass
我是 objective-c 的新手。
我不明白该怎么做,当您启动程序时会自动插入保存在 NSTextFiel 和 NSSecureTextField 中的姓氏。
我保存用户名和密码:
- (void)saveLoginPass {
if ([checkBox state]==NSOnState) {
[SSKeychain setPassword:self.passwordField.stringValue forService:@"ERClient" account:self.loginField.stringValue];
NSLog(@"Login/pass save");
}
else if([checkBox state]==NSOffState){
NSLog(@"Don't save login/pass");
}
}
和
[manager POST:URLString parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject){
if ([operation.responseString rangeOfString:@"mainBody"].location == NSNotFound) {
alertFild.stringValue=@"Login or pass false";
NSLog(@"Login or pass false");
NSLog(@"responseObject: %@", responseObject);
NSLog(@"operation.responseString: %@",operation.responseString);
NSLog(@"operation.response: %@",operation.response);
} else {
browserWindowController = [[ERBrowserWindowController alloc] initWithWindowNibName:@"ERBrowserWindowController"];
[browserWindowController showWindow:self];
[browserWindowController addDefaultTabs];
[self saveLoginPass];
[loginWindow close];
NSLog(@"Аuthorized");
}
}
我检查了Keychain 成功存储数据。
如何使实现在加载程序时插入最终登录名和密码?
我想你可以通过标准方式找回用户名和密码。
NSDictionary *credentials = [SSKeychain accountsForService:@"ERClient"].firstObject;
if (!credentials) {
return; // leave fields empty
}
NSString *accountName = credentialsDictionary[kSSKeychainAccountKey];
NSString *password = [SSKeychain passwordForService:@"ERClient" account:accountName];
// populate fields
}
我是 objective-c 的新手。 我不明白该怎么做,当您启动程序时会自动插入保存在 NSTextFiel 和 NSSecureTextField 中的姓氏。 我保存用户名和密码:
- (void)saveLoginPass {
if ([checkBox state]==NSOnState) {
[SSKeychain setPassword:self.passwordField.stringValue forService:@"ERClient" account:self.loginField.stringValue];
NSLog(@"Login/pass save");
}
else if([checkBox state]==NSOffState){
NSLog(@"Don't save login/pass");
}
}
和
[manager POST:URLString parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject){
if ([operation.responseString rangeOfString:@"mainBody"].location == NSNotFound) {
alertFild.stringValue=@"Login or pass false";
NSLog(@"Login or pass false");
NSLog(@"responseObject: %@", responseObject);
NSLog(@"operation.responseString: %@",operation.responseString);
NSLog(@"operation.response: %@",operation.response);
} else {
browserWindowController = [[ERBrowserWindowController alloc] initWithWindowNibName:@"ERBrowserWindowController"];
[browserWindowController showWindow:self];
[browserWindowController addDefaultTabs];
[self saveLoginPass];
[loginWindow close];
NSLog(@"Аuthorized");
}
}
我检查了Keychain 成功存储数据。 如何使实现在加载程序时插入最终登录名和密码?
我想你可以通过标准方式找回用户名和密码。
NSDictionary *credentials = [SSKeychain accountsForService:@"ERClient"].firstObject;
if (!credentials) {
return; // leave fields empty
}
NSString *accountName = credentialsDictionary[kSSKeychainAccountKey];
NSString *password = [SSKeychain passwordForService:@"ERClient" account:accountName];
// populate fields
}