Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- checking login and password in iphone
- -(void)checkindatabase{
- NSArray *dirPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *docDir =[dirPath objectAtIndex:0];
- NSString *databasePath =[[NSString alloc] initWithString:[docDir stringByAppendingPathComponent:@"login.db"]];
- if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
- {
- NSLog(@"open");
- NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where Username='%@' and Password='%@'",loginName.text,password.text]; //[sql UTF8String];
- //NSLog(@"'%s'",[sql UTF8String]);
- sqlite3_stmt *statement;
- if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK)
- { if(sqlite3_step(statement) == SQLITE_ROW)
- {
- //user name is correct
- //if u want to print in log use below code
- homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil];
- hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
- [self presentModalViewController:hvc animated: YES];
- }
- else {
- UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Failed!!!"
- message:@"Check your PId and Password" delegate:nil
- cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- }}
- sqlite3_finalize(statement);
- }
- sqlite3_close(database);
- }
- -(IBAction)homePage: (id)sender
- {
- [self checkindatabase];
- }
- -(BOOL)checkindatabase
- {
- NSArray *dirPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *docDir =[dirPath objectAtIndex:0];
- NSString *databasePath =[[NSString alloc] initWithString:[docDir stringByAppendingPathComponent:@"login.db"]];
- if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
- {
- NSLog(@"open");
- NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where Username='%@' and Password='%@'",loginName.text,password.text]; //[sql UTF8String];
- //NSLog(@"'%s'",[sql UTF8String]);
- sqlite3_stmt *statement;
- if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK)
- { if(sqlite3_step(statement) == SQLITE_ROW)
- {
- //user name is correct
- //if u want to print in log use below code
- return YES;
- }
- }
- sqlite3_finalize(statement);
- }
- sqlite3_close(database);
- return NO;
- }
- -(IBAction)homePage: (id)sender
- {
- if( [self checkindatabase] )
- {
- homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil];
- hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
- [self presentModalViewController:hvc animated: YES];
- [hvc release];
- }
- else
- {
- UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Failed!!!"
- message:@"Check your PId and Password" delegate:nil
- cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
- }
- -(BOOL)checkindatabase{
- NSArray *dirPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *docDir =[dirPath objectAtIndex:0];
- NSString *databasePath =[[NSString alloc] initWithString:[docDir stringByAppendingPathComponent:@"login.db"]];
- if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
- {
- NSLog(@"open");
- NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where Username='%@' and Password='%@'",loginName.text,password.text]; //[sql UTF8String];
- //NSLog(@"'%s'",[sql UTF8String]);
- sqlite3_stmt *statement;
- if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK)
- { if(sqlite3_step(statement) == SQLITE_ROW)
- {
- //user name is correct
- //if u want to print in log use below code
- flag = YES;
- }
- else {
- UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Failed!!!"
- message:@"Check your PId and Password" delegate:nil
- cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
- [alert release];
- flag = NO;
- }}
- sqlite3_finalize(statement);
- }
- sqlite3_close(database);
- return flag;
- }
- -(IBAction)homePage: (id)sender
- {
- BOOL newFlag = [self checkindatabase];
- if(newFlag)
- {
- homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil]
- hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
- [self presentModalViewController:hvc animated: YES];
- }
- }
Add Comment
Please, Sign In to add comment