2011-12-14 2 views
0

안녕하세요, 저는 SQLite를 사용하여 내 앱의 로그인과 비밀번호를 만들려고합니다. 모든 것이 괜찮지 만 일단 로그인 버튼을 누르면 홈 페이지에 입력되지 않습니다 !!! !아이폰의 로그인과 비밀번호 확인하기

Aadhira에 의해 제안
-(void)checkindatabase{ 

    NSArray *dirPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *docDir =[dirPath objectAtIndex:0]; 
    NSString *databasePath =[[NSString alloc] initWithString:[docDir stringByAppendingPathComponent:@"login.db"]]; 


    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) 
    { 
     NSLog(@"open"); 
     NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where Username='%@' and Password='%@'",loginName.text,password.text];  //[sql UTF8String]; 
     //NSLog(@"'%s'",[sql UTF8String]); 
     sqlite3_stmt *statement; 
      if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK) 
      { if(sqlite3_step(statement) == SQLITE_ROW) 
      { 
       //user name is correct 
       //if u want to print in log use below code 
       homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil]; 
       hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; 
       [self presentModalViewController:hvc animated: YES]; 

      } 
      else { 
       UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Failed!!!" 
                   message:@"Check your PId and Password" delegate:nil 
                 cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
       [alert show]; 

       }}    

     sqlite3_finalize(statement); 

    } 
    sqlite3_close(database); 
} 
-(IBAction)homePage: (id)sender 
{ 
    [self checkindatabase]; 

} 
+1

'checkindatabase' 메소드가 자격 증명의 유효성 여부에 관계없이 bool을 반환하도록하십시오. bool 값을 확인한 다음 UIAlertView가 표시되는지 아니면 사용자의 집보기가 해당 값을 사용하는지 표시하십시오. – Ilanchezhian

+0

안녕하세요 @ Aadhira, @ Dshan 당신이 내 코드는 내가 그것을하고있다면 오류를 보여주고 있기 때문에 @ Bshay 방법을 보여 주시기 바랍니다 코드의 형태로 BOOL 메서드를 보여줄 수 있습니다 – makumar

답변

0

...

는 반환 형식 BOOLcheckindatabase을 확인하고 로그인 성공 FALSE, 그렇지 않은 경우 TRUE을 반환 :

아래에있는 내 코드를 찾아주십시오.

그러면 BOOL 값을 기준으로 홈 페이지로 이동합니다.

IBAction 메서드를 수행하는 동안 다른 기능을 사용하여보기를 탐색 할 수 없습니다.

편집

: 나는 당신의 데이터베이스 코드를 찾고 있지 않다

은 .. 나는 단순히 방법으로 어떻게 어떤 당신이 직면 한 경우에도 오류를 언급 .... BOOL 반환 값을 사용하는 방법을 보여 주었다.

-(BOOL)checkindatabase{ 

    NSArray *dirPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *docDir =[dirPath objectAtIndex:0]; 
    NSString *databasePath =[[NSString alloc] initWithString:[docDir stringByAppendingPathComponent:@"login.db"]]; 


    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) 
    { 
     NSLog(@"open"); 
     NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where Username='%@' and Password='%@'",loginName.text,password.text];  //[sql UTF8String]; 
     //NSLog(@"'%s'",[sql UTF8String]); 
     sqlite3_stmt *statement; 
      if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK) 
      { if(sqlite3_step(statement) == SQLITE_ROW) 
      { 
       //user name is correct 
       //if u want to print in log use below code 
       flag = YES; 

      } 
      else { 
       UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Failed!!!" 
                   message:@"Check your PId and Password" delegate:nil 
                 cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
       [alert show]; 
       [alert release]; 
       flag = NO; 

       }}    

     sqlite3_finalize(statement); 

    } 
    sqlite3_close(database); 
    return flag; 
} 
-(IBAction)homePage: (id)sender 
{ 
    BOOL newFlag = [self checkindatabase]; 
    if(newFlag) 
    { 
     homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil] 
     hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; 
     [self presentModalViewController:hvc animated: YES]; 
    } 
} 
+0

내 코드는 내가 오류가 표시되기 때문에 코드의 형태로 BOOL 메서드를 보여 주시겠습니까 그것을하는 것 – makumar

+0

나는 나의 대답을 최신 정보로 업데이트했다. .. 그것을 보아라. ... 또한, SO 사용자로부터의 더 좋은 응답을위한 대답을 받아들이도록해라. ..njoy 코딩. .. :) – DShah

+0

HI DShah : 여기의 기가 무엇인가? – makumar

1

요청한대로 코드를 찾으십시오.

-(BOOL)checkindatabase 
{ 
    NSArray *dirPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *docDir =[dirPath objectAtIndex:0]; 
    NSString *databasePath =[[NSString alloc] initWithString:[docDir stringByAppendingPathComponent:@"login.db"]]; 

    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) 
    { 
     NSLog(@"open"); 
     NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where Username='%@' and Password='%@'",loginName.text,password.text];  //[sql UTF8String]; 
     //NSLog(@"'%s'",[sql UTF8String]); 
     sqlite3_stmt *statement; 
     if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK) 
     { if(sqlite3_step(statement) == SQLITE_ROW) 
      { 
       //user name is correct 
       //if u want to print in log use below code 
       return YES; 
      } 
     }    
     sqlite3_finalize(statement); 
    } 
    sqlite3_close(database); 
    return NO; 
} 

-(IBAction)homePage: (id)sender 
{ 
    if([self checkindatabase]) 
    { 
     homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil]; 
     hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; 
     [self presentModalViewController:hvc animated: YES]; 
     [hvc release]; 
    } 
    else 
    { 
     UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Failed!!!" 
                 message:@"Check your PId and Password" delegate:nil 
               cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
    } 

} 
+0

항상 유효하지 않습니다. – makumar

+0

그러면 sqlite 코드에 문제가있을 수 있습니다. – Ilanchezhian

+0

Aadhira : 코드를 따라 가면 정확한 로그인을위한 초대장이 보입니다 !!!!!!!! 만약 내가 Dshah의 코드를 따라 가면 페이지는 알려지지 않은 암호와 ID, !!!!!!!! – makumar

관련 문제