密码输入错误一定次数断开连接
1 /*---------------------------------------------------------------------------
2 * Received a server challenge:AuthenticationChallenge
3 *--------------------------------------------------------------------------*/
4 - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
5 {
6 // Access has failed two times...
7 if ([challenge previousFailureCount] > 3)
8 {
9 [urlConnection release];
10
11 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Authentication Error"
12 message:"Too many unsuccessul login attempts."
13 delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
14
15 [alert show];
16 [alert release];
17 }
18 else
19 {
20 // Answer the challenge
21 NSURLCredential *cred = [[[NSURLCredential alloc] initWithUser:@"admin"
22 password:@"password"
23 persistence:NSURLCredentialPersistenceForSession] autorelease];
24 [[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];
25 }
26 }