title: How to create login condition and core data table values can't be stored twice
body: <p>I have some problem on my project. Login form of my mobile app attached to PHP Login service and performing well too.I am also added core-data. In core data table, user id text field and password text field of login form and their data store in local DB, work properly.</p>
  <p>But I want, when user login at the first time, then the values are stored in local database value store and when the user log out from here and second time user login with same login id and password at that time database cannot record twice.</p>
  <p>Clearly, I want values can't be stored twice. please suggest how it works.</p>
  <h1>MY CODE</h1>
  <pre><code>- (IBAction)btn_action:(id)sender {
     if([[self.tx_userid text] isEqualToString:@&quot;&quot;] || [[self.tx_password text] isEqualToString:@&quot;&quot;] ) {
      
      } 
     else {
      
      NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@&quot;MYURL&quot;]];
      
      
      //create the Method &quot;GET&quot; or &quot;POST&quot;
      [request setHTTPMethod:@&quot;POST&quot;];
      
      
      //Pass The String to server(YOU SHOULD GIVE YOUR PARAMETERS INSTEAD OF MY PARAMETERS)
      NSString *userUpdate =[NSString stringWithFormat:@&quot;loginid=%@&amp;loginpassword=%@&quot;,_tx_userid.text,_tx_password.text, nil];
      
      
      
      //Check The Value what we passed
      NSLog(@&quot;the data Details is =%@&quot;, userUpdate);
      
      //Convert the String to Data
      NSData *data1 = [userUpdate dataUsingEncoding:NSUTF8StringEncoding];
      
      //Apply the data to the body
      [request setHTTPBody:data1];
      
      //Create the response and Error
      NSError *err;
      NSURLResponse *response;
      
      NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;err];
      
      //  if ([response statusCode] &gt;= 200 &amp;&amp; [response statusCode] &lt; 300)
      {
          
          
          NSError *error = nil;
          NSDictionary *jsonData = [NSJSONSerialization
                                    JSONObjectWithData:responseData
                                    options:NSJSONReadingMutableContainers
                                    error:&amp;error];
          
          int success = [jsonData[@&quot;success&quot;] integerValue];
          
          
          if(success == 1)
          {
              // stored in local DB
              NSManagedObjectContext *context = [self managedObjectContext];
              
              NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@&quot;Loginuser&quot; inManagedObjectContext:context];
              
              [newDevice setValue:self.tx_userid.text forKey:@&quot;userid&quot;];
              [newDevice setValue:self.tx_password.text forKey:@&quot;password&quot;];
              
              NSError *error = nil;
              // Save the object to persistent store
              if (![context save:&amp;error]) {
                  NSLog(@&quot;Can't Save! %@ %@&quot;, error, [error localizedDescription]);
              }
  
              NSLog(@&quot;Login SUCCESS&quot;);
              [self performSegueWithIdentifier:@&quot;login_success&quot; sender:self];
          } else {
              
              NSString *error_msg = (NSString *) jsonData[@&quot;error_message&quot;];
              [self alertStatus:error_msg :@&quot;Sign in Failed!&quot; :0];
          }
          
      }
      
  }
  
  
  
  
  NSLog(@&quot;app dir: %@&quot;,[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);
  
  
    }
  
   - (void) alertStatus:(NSString *)msg :(NSString *)title :(int) tag
  {
  UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
                                                      message:msg
                                                     delegate:self
                                            cancelButtonTitle:@&quot;Ok&quot;
                                            otherButtonTitles:nil, nil];
  alertView.tag = tag;
  [alertView show];
   }
  </code></pre>