This is my first try at iOS development. That being said, I am trying to md5 a password
This is my .m file
#import "SMViewController.h"
#import <CommonCrypto/CommonDigest.h> // Need to import for CC_MD5 access
@interface SMViewController ()
@end
@implementation SMViewController
.........
.........
.........
- (IBAction)buttonLoginClicked:(id)sender {
@try {
if([[self.textEmail text] isEqualToString:@""] || [[self.textPassword text] isEqualToString:@""] ) {
[self alertStatus:@"Please enter both Username and Password" :@"Login Failed!"];
} else {
/*String parameters = parametersData + "&controler=" + user + "&function=" + login + "&json=&client_type=android_client&client_id=" + GCMRegistrar.getRegistrationId(context) + "&ver="+VER;*/
NSString *post =[[NSString alloc] initWithFormat:@"email=%@&pass=%@&controler=user&function=login&json=&client_type=ip_client&client_id=x&ver=1321",[self.textEmail text],[self.textPassword text]];
…………………………….
………
……..
……
}
- (IBAction)backgroundClick:(id)sender {
[self.textPassword resignFirstResponder];
[self.textEmail resignFirstResponder];
}
@end
@implementation NSString (MyExtensions)
- (NSString *)md5
{
const char *cStr = [self UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
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]
];
}
@end
@implementation NSData (MyExtensions)
- (NSString*)md5
{
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5( self.bytes, self.length, 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]
];
}
@end
my .h file:
@interface NSString (MyExtensions)
- (NSString *)md5;
@end
@interface NSData (MyExtensions)
- (NSString*)md5;
@end
How can I pass the textPassword to the md5
this is based on MD5 algorithm in Objective C