如何在sqlite FMBD中检查用户名和密码是否正确

时间:2014-05-08 09:14:46

标签: ios sqlite fmdb

我想检查用户是否输入了正确的用户名和密码。 我用许多用户名和密码创建了数据库。 提前谢谢。

-(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");

        }
    } 
}

1 个答案:

答案 0 :(得分:0)

你方法的主体

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];