Implementation .m file:
#import "NSString+Hash.h" @implementation NSString (Hash) +(NSString*)randomSaltWithLength:(int)length { char chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; NSMutableString* ret = [[[NSMutableString alloc] initWithCapacity:length] autorelease]; srandomdev(); for(int i=0;i<length;i++) { int index = random()%52; char a = chars[index]; [ret appendString:[NSString stringWithCString:&a length:1]]; } return ret; } @end
.h file:
@interface NSString (Hash) +(NSString*)randomSaltWithLength:(int)length; @end