1

I am developing an application, i want to know how to achive forget password scenario in iPhone.

When user forget their password then I have a button in my app when i click on it UIAlertView open in which i have a textfield, user must enter their email address and the password get mail on that mail id.

How can I do that I have define a action for button this is the code:

-(IBAction)forgetpassword:(id)sender
{
    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Forget Password" message:@"Please Enter your Email address " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    av.alertViewStyle = UIAlertViewStylePlainTextInput;
    [av textFieldAtIndex:0].delegate = self;
    [av show];
}

but what i need is just require the code to which i can use and mail the password to the email id which user will entered.

0

1 Answer 1

1

just add delegate MFMessageComposeViewControllerDelegate to the .h file and then use this code when you want to email and also add framework MessageUI.framework in the project

-(IBAction)forgetpassword:(id)sender
{
     if ([MFMailComposeViewController canSendMail]) 
     {

        MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
        NSString *mailBody = @"your Message";


        [mailComposeViewController setMessageBody:mailBody isHTML:NO];
        mailComposeViewController.mailComposeDelegate = self;
        [self presentViewController:mailComposeViewController animated:YES completion:nil];
    } 
    else 
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"e-Mail Sending Alert"
                                                        message:@"You can't send a mail"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK" 
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

and this bellow method is delegate method of MFMessageComposeViewControllerDelegate

#pragma mark - MFMessage Delegate

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    if (result == MFMailComposeResultSent) 
    {
        NSLog(@"\n\n Email Sent");
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

you can also use SKPSMTPmessage web-service for send e-mail

i hope this help you...

4
  • can you tell me where to add above code is simple i add that in (ibaction)forgetpassword method
    – raza
    Nov 26, 2012 at 8:34
  • you want to sent mail when user click on ok button of AlertView?? Nov 26, 2012 at 8:36
  • @raza just remove the alertview and add the above code in your forgetpassword method Nov 26, 2012 at 8:38
  • @raza but the email sent through MFMailComposeViewController will be seen by the user and hence no meaning of sending email. User can read email that is being sent so use less approach. U can use SKPSMTPMessage / some webservice that do this task to make your password more secure Nov 26, 2012 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.