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 9232057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:13:23+00:00 2026-06-18T06:13:23+00:00

I have noticed that in my application i’m doing. When I register a username

  • 0

I have noticed that in my application i’m doing. When I register a username for example “Username” and when I try to log in with “username” it doesn’t let me in but when I try “Username” it does. Can anyone tell me how to fix it? Here is my code.
Register:

#import "ViewController2.h"

@interface ViewController2 ()

@end

@implementation ViewController2
@synthesize tbPassword,tbRepass,tbUsername;
-(void) createTable: (NSString *) UserTable
      withUserField: (NSString *) UserField
      withPassField: (NSString *) PassField;
{
    char *err;
    NSString *sql = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS '%@' ('%@' " "TEXT PRIMARY KEY, '%@' TEXT);", UserTable, UserField,PassField];
    if (sqlite3_exec(users, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK) {
        sqlite3_close(users);
        NSAssert(0, @"Could not create table");

    }
    else{
        NSLog(@"table created");
    }
}

-(NSString *) filePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"users.sql"];
}

-(void) openDB {
    if (sqlite3_open([[self filePath]UTF8String],&users) != SQLITE_OK){
        sqlite3_close(users);
        NSAssert(0, @"Database failed to open");
    }
    else{
        NSLog(@"database opened");
    }
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [self openDB];
    [self createTable:@"UserAccount" withUserField:@"Username" withPassField:@"Password"];
    self.tbUsername.delegate=self;
    self.tbPassword.delegate=self;
    self.tbRepass.delegate=self;
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnRegister:(id)sender
{
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM UserAccount WHERE Username = '%s'",[tbUsername.text UTF8String]];
    sqlite3_stmt *statement;
    if (sqlite3_prepare(users, [select UTF8String], -1, &statement, nil)==SQLITE_OK)
    {
        if(sqlite3_step(statement)==SQLITE_ROW)
        {

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Username already exist!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];

        }
        else
        {
           if ([tbUsername.text isEqualToString:@""])
            {

                UIAlertView *alert2 = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please enter a username." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert2 show];
            }
            else if([tbPassword.text length]==0 || [tbRepass.text length]==0)
            {

                UIAlertView *alert3 = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please enter a password." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert3 show];
            }
            else if([tbPassword.text length]>0 && [tbRepass.text length]>0)
            {

                if([tbPassword.text isEqualToString:tbRepass.text])
                {
                    NSLog(@"Password Match");
                    NSString *username = tbUsername.text;
                    NSString *pass = tbPassword.text;

                    NSString *sql = [NSString stringWithFormat:@"INSERT INTO UserAccount ('Username','Password') VALUES ('%@','%@')",username,pass];
                    char *err;
                    if (sqlite3_exec(users, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK)
                    {
                        sqlite3_close(users);
                        NSAssert(0, @"Could not update table)");

                    }
                    else
                    {
                        NSLog(@"table updated");
                        UIAlertView *alert4 = [[UIAlertView alloc]initWithTitle:@"Done" message:@"Account was registered successfully!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                        [alert4 show];
                        ViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
                        VC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

                       [self presentViewController:VC animated:YES completion:nil];

                        tbUsername.text = @"";
                        tbPassword.text = @"";


                    }

                }

                else
                {
                    UIAlertView *alert5 = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Password does not match." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [alert5 show];
                }
            }
        }
    }
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [[self tbUsername]resignFirstResponder];
    [[self tbPassword]resignFirstResponder];
    [[self tbRepass]resignFirstResponder];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    return [textField resignFirstResponder];
}
@end

Log In:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize tbPassword,tbUsername;
-(void) createTable: (NSString *) UserTable
      withUserField: (NSString *) UserField
      withPassField: (NSString *) PassField;
{
    char *err;
    NSString *sql = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS '%@' ('%@' " "TEXT PRIMARY KEY, '%@' TEXT);", UserTable, UserField,PassField];
    if (sqlite3_exec(users, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK) {
        sqlite3_close(users);
        NSAssert(0, @"Could not create table");

    }
    else{
        NSLog(@"table created");
    }
}

-(NSString *) filePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"users.sql"];
}

-(void) openDB {
    if (sqlite3_open([[self filePath]UTF8String],&users) != SQLITE_OK){
        sqlite3_close(users);
        NSAssert(0, @"Database failed to open");
    }
    else{
        NSLog(@"database opened");
    }
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [self openDB];
    [self createTable:@"UserAccount" withUserField:@"Username" withPassField:@"Password"];
    self.tbUsername.delegate=self;
    self.tbPassword.delegate=self;
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnLogin:(id)sender {
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM UserAccount WHERE Username = '%s' and Password = '%s'",[tbUsername.text UTF8String],[tbPassword.text UTF8String]];
    sqlite3_stmt *statement;
    if (sqlite3_prepare(users, [select UTF8String], -1, &statement, nil)==SQLITE_OK)
    {
        if(sqlite3_step(statement)==SQLITE_ROW)
        {
            ViewController3 *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController3"];
            VC.strUsername = self.tbUsername.text;
            [self presentViewController:VC animated:YES completion:nil];

        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Authentication Failed" message:@"Wrong Username/Password!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }

    }
}

- (IBAction)btnRegister:(id)sender {
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [[self tbUsername]resignFirstResponder];
    [[self tbPassword]resignFirstResponder];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    return [textField resignFirstResponder];
}
@end

brb got classes.

  • 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-18T06:13:24+00:00Added an answer on June 18, 2026 at 6:13 am

    Change your query.

    NSString *select = [NSString stringWithFormat:@"SELECT * FROM UserAccount WHERE Username = '%s' COLLATE NOCASE and Password = '%s'",[tbUsername.text UTF8String],[tbPassword.text UTF8String]];
    

    I think this will help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have noticed that my application's Document folder is sometimes different. The workflow was
While debugging a problem in a WPF application, I have noticed that the TwoWay
I have created a Visual Studio 2010 ASP.NET Web Application. I've noticed that if
I have an older web application that uses a MySQL Database (MYISAM). I noticed
I need to localize an application and have noticed that several countries don't appear
I'm currently investigating the performance of a JSF application. I have noticed that code
I use Toast dialogs a lot throughout my application. However, I have noticed that
When debugging a VB6 application, I have noticed that the VB6 IDE keeps any
I've launched an application last week and have noticed since that in Chrome only
I am just starting my first MVC Web Application and have noticed that I

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.