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

  • SEARCH
  • Home
  • 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 5933643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:00:08+00:00 2026-05-22T15:00:08+00:00

I met a problem while trying to passing the inputed strings of Textfield to

  • 0

I met a problem while trying to passing the inputed strings of Textfield to calculate MD5.

When I just give a specified string, like abc, in my code, and do the MD5 calculation, it will return a correct result.

Things went wrong when I try to using a textfield to let the user input the same string, abc, and then I pass the textfield.text to md5 function to do the md5 hash. This time, the result was different.

I am totally confused with this problem and have been got stuck at there for nearly a week, but just couldn’t figure out why and how to solve it.

Could you please help me with that?

here’s my code:

Hello_MD5ViewController.h

//
//  Hello_MD5ViewController.h
//  Hello-MD5
//
//

#import <UIKit/UIKit.h>

@interface Hello_MD5ViewController : UIViewController {
    UILabel *md5Text;
    UITextField *plainText;

}
@property (nonatomic, retain) IBOutlet UILabel *md5Text;
- (IBAction)buttonPressed: (id)sender;
@end

Hello_MD5ViewController.m

//
//  Hello_MD5ViewController.m
//  Hello-MD5
//

#import "Hello_MD5ViewController.h"
#import <CommonCrypto/CommonDigest.h> //Import for CC_MD5 access

NSString* md5(NSString *str)
{
    const char *cStr = [str UTF8String];
    unsigned char result[16];
    CC_MD5(cStr, strlen(cStr), result); //This is the MD5 call
    return [NSString stringWithFormat:
            @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 
            result[0], result[1], result[2], result[3], 
            result[4], result[5], result[6], result[7], 
            result[8], result[9], result[10], result[11], 
            result[12], result[13], result[14], result[15]
            ];
}


@implementation Hello_MD5ViewController
@synthesize md5Text;

- (IBAction)buttonPressed:(id)sender {
    NSString *input = [[NSString alloc] initWithString: plainText.text];
    NSString *digest = md5(input); //if I use textfield.text to passing the string, the result will be wrong
    //NSString *digest = md5(@"123"); //if I give a string within code like this, it'll return correct result
    NSString *md5Result = [[NSString alloc] initWithFormat:
                           @"MD5 RESULT \n%@", digest];
    md5Text.text = md5Result;
    //Calculate MD5 value
}

- (void)dealloc
{
    [plainText release];
    [md5Text release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.md5Text = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Thank you for your help!

=====UPDATED VERSION @ GMT+1 0251 hrs 05/21/2011=======

Hello_MD5ViewController.h

//  Hello-MD5
//
//

#import <UIKit/UIKit.h>

/*@interface NSString (md5Extension)
- (NSString *) md5;
@end

@interface NSData (md5Extension)
- (NSString *) md5;
@end
*/
@interface Hello_MD5ViewController : UIViewController {
    UILabel *md5Text;
    UITextField *plainText;

}
//@property (nonatomic, retain) NSString *input;
@property (nonatomic, retain) IBOutlet UILabel *md5Text;
- (IBAction)buttonPressed: (id)sender;
@property (nonatomic, retain) IBOutlet UITextField *plaintext;
@end

Hello_MD5ViewController.m

//  Hello-MD5


#import "Hello_MD5ViewController.h"
#import <CommonCrypto/CommonDigest.h> //Import for CC_MD5 access

NSString* md5(NSString *str)
{
    const char *cStr = [str UTF8String];
    unsigned char result[16];
    CC_MD5(cStr, strlen(cStr), result); //This is the MD5 call
    return [NSString stringWithFormat:
            @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 
            result[0], result[1], result[2], result[3], 
            result[4], result[5], result[6], result[7], 
            result[8], result[9], result[10], result[11], 
            result[12], result[13], result[14], result[15]
            ];
}

@implementation Hello_MD5ViewController
@synthesize md5Text;
@synthesize plaintext;

- (IBAction)buttonPressed:(id)sender {
    //NSString *input = [[NSString alloc] initWithString: plainText.text];
    if(plainText.text == nil)
    {
        NSLog(@"Disconnected.");
    }
    //NSLog(@"Output %@",plainText.text);
    //NSString *digest = md5(input);
    //NSString *digest = md5(@"123");
    //NSString *md5Result = [[NSString alloc] initWithFormat:
                          // @"MD5 RESULT \n%@", digest];
    //md5Text.text = md5Result;
    //Calculate MD5 value
}

- (void)dealloc
{
    [plainText release];
    [md5Text release];
    //[input release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.md5Text = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
  • 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-05-22T15:00:09+00:00Added an answer on May 22, 2026 at 3:00 pm

    You haven’t defined an IBOutlet on plainText. It looks like the connection isn’t there. You are requesting text of a nil object and hence the incorrect output.

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

Sidebar

Related Questions

Just like hold on in Matlab. I met this problem when i want to
I have an implementation that just like gmail application, but have met some problem
I met a problem when trying @Singleton of Guice: import com.google.inject.Singleton; @Singleton public class
I have met an interesting problem while implementing the Observer pattern with C++ and
I met a problem while using python(2.6) cgi to show a mime data in
While i making some kind of jQuery image rotator, i met problem. Where is
I met a problem like this. class A have a list of class B.
folks, I met a weird problem while using mathematica. As you can see from
I met a problem which is very strange, my company uses Visual Source Safe
I met an interesting issue about C#. I have code like below. List<Func<int>> actions

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.