Câu trả lời quá muộn nhưng sẽ tốt cho trợ giúp trong tương lai. Dưới đây là những gì tôi đã làm để lưu mật khẩu trong Keychain của Mac
#pragma -mark Password save in Keychain
-(NSURLProtectionSpace *)createProtectionSpaceForBasicAuthentication{
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost:@"http://yourURLHere"
port:1804 //add Your port here
protocol:@"http" //can be pass as nil
realm:nil
authenticationMethod:NSURLAuthenticationMethodHTTPBasic];
return protectionSpace;
}
-(void)createCredentialForUsername:(NSString *)username Password:(NSString *)password{
NSURLCredential *credentialObject;
credentialObject = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistencePermanent];
[[NSURLCredentialStorage sharedCredentialStorage] setCredential:credentialObject forProtectionSpace:[self createProtectionSpaceForBasicAuthentication]];
}
Đối với tiết kiệm mật khẩu
- (IBAction)saveButtonClicked:(id)sender {
[self createCredentialForUsername:@"User_Name" Password:@"Your_Pass"];
}
cho việc lấy lại mật khẩu
NSURLCredential *credential;
NSDictionary *credentials;
credentials = [[NSURLCredentialStorage sharedCredentialStorage] credentialsForProtectionSpace:[self createProtectionSpaceForBasicAuthentication]];
credential = [credentials.objectEnumerator nextObject];
NSLog(@"Username: %@ and password %@", credential.user, credential.password);
Khi chúng tôi chạy ứng dụng để lấy mật khẩu, chúng tôi sẽ nhận được lời nhắc hành động người dùng để truy cập vào keychain.
Nguồn
2017-07-28 13:00:21
Điều này có thể hoạt động, mặc dù tôi đã nghĩ mật khẩu internet có vẻ tốt hơn một chút so với kết hợp với thiết lập của tôi so với hệ thống mật khẩu chung. Tôi đoán tôi có thể mã hóa url vào "dịch vụ" mà SSKeychain sử dụng làm định danh. Nếu không có bất cứ điều gì tốt hơn cho mục đích của tôi, ít nhất đây là một điểm khởi đầu nếu tôi muốn đặt cùng một hệ thống xung quanh các mật khẩu internet. – Noah