Guest User

Untitled

a guest
Aug 10th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. checking login and password in iphone
  2. -(void)checkindatabase{
  3.  
  4. NSArray *dirPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  5. NSString *docDir =[dirPath objectAtIndex:0];
  6. NSString *databasePath =[[NSString alloc] initWithString:[docDir stringByAppendingPathComponent:@"login.db"]];
  7.  
  8.  
  9. if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
  10. {
  11. NSLog(@"open");
  12. NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where Username='%@' and Password='%@'",loginName.text,password.text]; //[sql UTF8String];
  13. //NSLog(@"'%s'",[sql UTF8String]);
  14. sqlite3_stmt *statement;
  15. if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK)
  16. { if(sqlite3_step(statement) == SQLITE_ROW)
  17. {
  18. //user name is correct
  19. //if u want to print in log use below code
  20. homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil];
  21. hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
  22. [self presentModalViewController:hvc animated: YES];
  23.  
  24. }
  25. else {
  26. UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Failed!!!"
  27. message:@"Check your PId and Password" delegate:nil
  28. cancelButtonTitle:@"OK" otherButtonTitles:nil];
  29. [alert show];
  30.  
  31. }}
  32.  
  33. sqlite3_finalize(statement);
  34.  
  35. }
  36. sqlite3_close(database);
  37. }
  38. -(IBAction)homePage: (id)sender
  39. {
  40. [self checkindatabase];
  41.  
  42. }
  43.  
  44. -(BOOL)checkindatabase
  45. {
  46. NSArray *dirPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  47. NSString *docDir =[dirPath objectAtIndex:0];
  48. NSString *databasePath =[[NSString alloc] initWithString:[docDir stringByAppendingPathComponent:@"login.db"]];
  49.  
  50. if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
  51. {
  52. NSLog(@"open");
  53. NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where Username='%@' and Password='%@'",loginName.text,password.text]; //[sql UTF8String];
  54. //NSLog(@"'%s'",[sql UTF8String]);
  55. sqlite3_stmt *statement;
  56. if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK)
  57. { if(sqlite3_step(statement) == SQLITE_ROW)
  58. {
  59. //user name is correct
  60. //if u want to print in log use below code
  61. return YES;
  62. }
  63. }
  64. sqlite3_finalize(statement);
  65. }
  66. sqlite3_close(database);
  67. return NO;
  68. }
  69.  
  70. -(IBAction)homePage: (id)sender
  71. {
  72. if( [self checkindatabase] )
  73. {
  74. homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil];
  75. hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
  76. [self presentModalViewController:hvc animated: YES];
  77. [hvc release];
  78. }
  79. else
  80. {
  81. UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Failed!!!"
  82. message:@"Check your PId and Password" delegate:nil
  83. cancelButtonTitle:@"OK" otherButtonTitles:nil];
  84. [alert show];
  85. [alert release];
  86. }
  87.  
  88. }
  89.  
  90. -(BOOL)checkindatabase{
  91.  
  92. NSArray *dirPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  93. NSString *docDir =[dirPath objectAtIndex:0];
  94. NSString *databasePath =[[NSString alloc] initWithString:[docDir stringByAppendingPathComponent:@"login.db"]];
  95.  
  96.  
  97. if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
  98. {
  99. NSLog(@"open");
  100. NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where Username='%@' and Password='%@'",loginName.text,password.text]; //[sql UTF8String];
  101. //NSLog(@"'%s'",[sql UTF8String]);
  102. sqlite3_stmt *statement;
  103. if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE_OK)
  104. { if(sqlite3_step(statement) == SQLITE_ROW)
  105. {
  106. //user name is correct
  107. //if u want to print in log use below code
  108. flag = YES;
  109.  
  110. }
  111. else {
  112. UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Login Failed!!!"
  113. message:@"Check your PId and Password" delegate:nil
  114. cancelButtonTitle:@"OK" otherButtonTitles:nil];
  115. [alert show];
  116. [alert release];
  117. flag = NO;
  118.  
  119. }}
  120.  
  121. sqlite3_finalize(statement);
  122.  
  123. }
  124. sqlite3_close(database);
  125. return flag;
  126. }
  127. -(IBAction)homePage: (id)sender
  128. {
  129. BOOL newFlag = [self checkindatabase];
  130. if(newFlag)
  131. {
  132. homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil]
  133. hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
  134. [self presentModalViewController:hvc animated: YES];
  135. }
  136. }
Add Comment
Please, Sign In to add comment