0

I want to check if the user has entered correct username and password or not. i have created the database with many username and passwords. Thanks in advance.

-(IBAction)LoginPressed:(id)sender{
    arrayofusername = [[NSMutableArray alloc] init];

    FMDatabase *database = [FMDatabase databaseWithPath:[self GetDBPath]];


    [database open];

    FMResultSet *results =[database executeQuery:@"SELECT * FROM RecordTable"];


       NSString *queryforchecking = [NSString stringWithFormat:@"SELECT * FROM RecordTable where username = '%@' and password = '%@'",L_usernameField.text,L_passwordField.text];

    results = [database executeQuery:queryforchecking];

    while ([results next]) {
        username = [results stringForColumn:@"username"];


        if ([username isEqualToString:queryforchecking]) {
            NSLog(@"matched");
        }

        else{
            NSLog(@"not matched");

        }
    } 
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

Body of your method

FMDatabase *database = [FMDatabase databaseWithPath:[self GetDBPath]];

[database open];

FMResultSet *results = [database executeQuery:@"SELECT * FROM RecordTable where username = ? and password = '?",L_usernameField.text,L_passwordField.text];

if ([results next]) {
    NSLog(@"matched");
} else{
    NSLog(@"not matched");
}

[database close];
Quver
  • 1,408
  • 14
  • 21