Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking Username and Password to match in SQLIte
    primarykey
    data
    text
    <p>How can I check if the Username and Password would be the same as the Username and Password in the Database.</p> <p>AppDelegate.m:</p> <pre><code>-(void) readLoginFromDatabase { // Setup the database object sqlite3 *database; // Init the Array lo = [[NSMutableArray alloc] init]; // Open the database from the users filessytem if(sqlite3_open([databasePath UTF8String], &amp;database) == SQLITE_OK) { // Setup the SQL Statement and compile it for faster access const char *sqlStatement = "Select * from Login"; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, sqlStatement, -1, &amp;compiledStatement, NULL) == SQLITE_OK) { // Loop through the results and add them to the feeds array while(sqlite3_step(compiledStatement) == SQLITE_ROW) { // Read the data from the result row NSString *aLoginName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; NSString *aLoginPass = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]; NSString *aLoginAccess = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)]; // Create a new object with the data from the database Login *los = [[Login alloc] initWithName:aLoginName pass:aLoginPass access:aLoginAccess]; // Add the object to the Array [lo addObject:los]; } } // Release the compiled statement from memory sqlite3_finalize(compiledStatement); } sqlite3_close(database); } </code></pre> <p>ViewController.m:</p> <pre><code>-(IBAction)buttonWasClicked:(id)sender { if ((userText.text != logins.loginUser) &amp;&amp; (passText.text != logins.loginPass)) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:[[NSString alloc] initWithFormat:@"Your Username/Password is incorrect!"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } else { StudentViewController *studentView = [self.storyboard instantiateViewControllerWithIdentifier:@"studentView"]; [studentView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; [self presentViewController:studentView animated:YES completion:nil]; } if (userText.text != logins.loginUser) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:[[NSString alloc] initWithFormat:@"Your Username is incorrect!"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } if (passText.text != logins.loginPass) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:[[NSString alloc] initWithFormat:@"Your Password is incorrect!"] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } } </code></pre> <p>Even when the Username and Password I type is exactly the same as in the database, it would still show me the error message instead of displaying the next view.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload