Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8140579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:12:31+00:00 2026-06-06T12:12:31+00:00

I am trying to create a login screen for an iphone application using sqlite3

  • 0

I am trying to create a login screen for an iphone application using sqlite3 to store the login credentials.

The following is the function I am using to handle the authentication:

-(void) enter
{
    const char *dbpath = [databasePath UTF8String];
    sqlite3_stmt    *statement;

    if (sqlite3_open(dbpath, &DBLogin) == SQLITE_OK)
    {
        NSLog(@"Connected to Database");
        NSString *querySQL = [NSString stringWithFormat:@"SELECT id FROM User WHERE id=\"%@\"",login.text];
        NSString *s = password.text;
        const char *query_stmt = [querySQL UTF8String];
        NSLog(@"String is %s",query_stmt);
        NSLog(@"Pass is %@",s);
        if (sqlite3_prepare_v2(DBLogin,query_stmt, -1, &statement, NULL) ==!SQLITE_NULL)
        {
            NSLog(@"Executed Correctly");
            querySQL = [NSString stringWithFormat:@"SELECT password FROM User WHERE password=\"%@\"",password.text];
            query_stmt = [querySQL UTF8String];
            const char *f= [login.text UTF8String];
            NSLog(@"String is %s",query_stmt);
            NSLog(@"Pass is %@",s);
            //   const char *l = [login.text UTF8String];
            //  sqlite3_bind_text(statement, 1, query_stmt, -1, SQLITE_STATIC);
            if (sqlite3_prepare_v2(DBLogin,query_stmt, -1, &statement, NULL) == !SQLITE_NULL)
            {
                if(sqlite3_bind_text(statement, 1,f , -1, SQLITE_STATIC))
                    status.text= @"Congratulations";
            }
            else
            {
                NSLog(@"error");
            }
        }
        else
        {
            NSLog(@"Failed");
            status.text =@"ERROR!";
        }
    }
}

And this is my schema for the database:

CREATE TABLE User (id varchar(20) PRIMARY KEY, password varchar(20));

I think there is something wrong with the way I am passing the details of login.text or password.text. According to NSLog it passes the right values but it seems to fail to check whether it is the right input or not. It seems to think everything is good and displays status.text = Congratulations no matter what I input.

I don’t have any idea how to fix this and would appreciate any help I can get. I can provide more information if needed. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:12:33+00:00Added an answer on June 6, 2026 at 12:12 pm

    From the code you posted, I want to make few things clear for you and then will suggest how to proceed. There are 4 main sqlite functions used to perform a database operation

    1. sqlite3_open : To open a database connection
    2. sqlite3_prepare_v2: To compile the query into byte-code program
    3. sqlite_bind : To pass input values to the query
    4. sqlite3_step : To evaluate/execute the compiled statement.

    So from the code you posted above,

    1. you have not performed step 4. So its obvious that you have not executed the query at all.
    2. you formed the query completely(including the input parameter) using NSString stringWithFormat method, so there is no need to use sqlite_bind function.
    3. The logic you used to authenticate user is also a bit confusing.

    Here is the way to achieve what you need

    if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
       const char *sql = "select * from User where id = ? and password = ?";
       sqlite3_stmt *selectstmt;
       if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
         sqlite3_bind_text(selectstmt, 1, [login.text UTF8String], -1, SQLITE_TRANSIENT);
         sqlite3_bind_text(selectstmt, 2, [password.text UTF8String], -1, SQLITE_TRANSIENT);
          while(sqlite3_step(selectstmt) == SQLITE_ROW) {
    
              NSLog(@"Successful login");
          }
       }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
I am trying to create a thread to handle a login function that is
Ok so I am trying create a login script, here I am using PHP5
I am new to zend. I am trying to create login form using zend
I'm trying to create a login system using PHP, and I'm not quite sure
I've got a few questions about edittext.. I'm trying to create a login screen
I'm trying to create a simple username/password login screen. I have the layout done,
I'm creating a Ruby on Rails application, and I'm trying to create/login/logout users. This
in my lightswitch application im trying to create a Customers Screen for customers who
Im trying to create a login authentication and when the user enters incorrect password

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.