密码输入错误一定次数断开连接
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 }

相关文章:

  • 2022-12-23
  • 2021-06-02
  • 2022-01-22
  • 2021-12-29
  • 2021-10-14
  • 2021-09-11
  • 2021-08-30
猜你喜欢
  • 2022-12-23
  • 2021-07-11
  • 2021-05-07
  • 2022-12-23
  • 2021-11-27
  • 2021-05-29
相关资源
相似解决方案