Password Generator for iphone


This tutorial is used for generating the password and send it through the mail to the required personal.

 

 

1.  Open the xcode & choose "File->New Project".

2.  Select "View Based Application" from left menu .

3.  Name your project as "PasswordGeneratorApp" and save the project.

4.  Then  select "PasswordGeneratorAppViewController.h" file from the left side menu or group and files. Then enter the following :

 

#import <UIKit/UIKit.h>

#import <MessageUI/MessageUI.h>

#import <MessageUI/MFMailComposeViewController.h>


@interface PasswordGeneratorAppViewController : UIViewController<MFMailComposeViewControllerDelegate> {

IBOutlet UILabel *passwordLengthLabel;

IBOutlet UISegmentedControl *segmentControl;

IBOutlet UISwitch *alphaNumericSwitch;

IBOutlet UISwitch *useSymbolsSwitch;

IBOutlet        UISlider *passwordSlider;

IBOutlet UIButton *passwordGenerator;

IBOutlet UITextField *passwordTextField;

IBOutlet UILabel *phoneticsLabel;

IBOutlet UIButton *sendEmail;

NSString *smallLetterString,*capitalLetterString,*specialSymbolString,*numericString;

NSDictionary *dic;

NSMutableString *phoneticString



}


@property(retain,nonatomic)UILabel *passwordLengthLabel;

@property(retain,nonatomic)UISegmentedControl *segmentControl;

@property(retain,nonatomic)UISwitch *alphaNumericSwitch;

@property(retain,nonatomic)UISwitch *useSymbolsSwitch;

@property(retain,nonatomic)UITextField *passwordTextField;

@property(retain,nonatomic)UILabel *phoneticsLabel;

@property(retain,nonatomic)NSString *pcl;

@property(retain,nonatomic)UISlider *passwordSlider;

@property(retain,nonatomic)UILabel *message;

@property(retain,nonatomic)NSString *smallLetterString,*capitalLetterString,*specialSymbolString,*numericString;

-(IBAction)createPassword;

-(IBAction)sendEmail;

-(IBAction)passwordLengthValue;


@property(retain,nonatomic)NSDictionary *dic;

@property(retain,nonatomic)NSMutableString *phoneticString; 


@end

 

 

 

5. Then  select "PasswordGeneratorAppViewController.m" file from the left side menu or group and files.

 


#import "PasswordGeneratorAppViewController.h"


@implementation PasswordGeneratorAppViewController

@synthesize passwordLengthLabel,passwordSlider,segmentControl,alphaNumericSwitch,useSymbolsSwitch,passwordTextField,phoneticsLabel,pcl;

@synthesize smallLetterString,capitalLetterString,specialSymbolString,numericString,dic,phoneticString,message;



-(IBAction)createPassword

{

NSMutableString *passwordString=[[NSMutableString alloc]initWithString:@""];

if ([passwordLengthLabel.text intValue]==0 || [passwordLengthLabel.text intValue]<6) {

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Please specify the password length that must be more than five in legth" delegate:self cancelButtonTitle:@"Okey" otherButtonTitles:nil,nil];

[alert show];

}

else {

switch (segmentControl.selectedSegmentIndex) {

case 0:

passwordString = [[NSMutableString alloc]initWithFormat:@"%@",smallLetterString];

NSLog(@"segment index = %@",passwordString);

break;

case 1:

passwordString = [[NSMutableString alloc]initWithFormat:@"%@%@",smallLetterString,capitalLetterString];

NSLog(@"segment index is 1 = %@",passwordString);

break;

        case 2:

passwordString = [[NSMutableString alloc]initWithFormat:@"%@",capitalLetterString];

NSLog(@"segment index is 1 = %@",passwordString);

break;


default:

break;

}

NSLog(@"just outside the switch case");

if (alphaNumericSwitch.on) {

[passwordString appendString:numericString];

}

if (useSymbolsSwitch.on) {

[passwordString appendString:specialSymbolString];

}

NSLog(@"%@",passwordString);

int k = passwordString.length;

NSMutableString *pass = [[NSMutableString alloc]initWithString:@""];

    for (int i =0;i<[passwordLengthLabel.text intValue];i++) {

int r = arc4random() %k ;

NSLog(@"%i",r);

NSString  *str =[[NSString alloc]initWithFormat:@"%c",[passwordString characterAtIndex:r]];

[pass appendString:str];

}

NSLog(@"password generated is = %@",pass);

    passwordTextField.text = pass;

passwordTextField.alpha = 0.8;

   

dic = [NSDictionary dictionaryWithObjectsAndKeys:

  @"One", @"1",

  @"Two", @"2",

  @"Three", @"3",

  @"Four", @"4",

  @"Five", @"5",

  @"Six", @"6",

  @"Seven", @"7",

  @"Eight", @"8",

  @"Nine", @"9",

  @"zero", @"0",

   

  @"Alpha",    @"A",

  @"Beta",     @"B",

  @"Charlie",   @"C",

  @"Delta",     @"D",

  @"Echo",     @"E",

  @"Foxtrot",   @"F",

  @"Golf",     @"G",

  @"Hotel",    @"H",

  @"India",    @"I",

  @"Juliet",    @"J",

  @"Kilo",     @"K",

  @"Lima",     @"L",

  @"Mike",     @"M",

  @"November"@"N",

  @"Oscar",     @"O",

  @"Papa",     @"P",

  @"Quebec",   @"Q",

  @"Romeo",    @"R",

  @"Sierra",   @"S",

  @"Tango",    @"T",

  @"Uniform",   @"U",

  @"Victor",   @"V",

  @"Whiskey" , @"W",

  @"X-ray",    @"X",

  @"Yankee",   @"Y",

  @"Zulu",     @"Z",

   

   

  @"alpha",   @"a",

  @"beta",    @"b",

  @"charlie"@"c",

  @"delta",   @"d",

  @"echo",    @"e",

  @"foxtrot", @"f",

  @"golf",    @"g",

  @"hotel",   @"h",

  @"india",   @"i",

  @"juliet" , @"j",

  @"kilo",    @"k",

  @"lima",    @"l",

  @"mike",    @"m",

  @"november", @"n",

  @"oscar",   @"o",

  @"papa",    @"p",

  @"quebec" , @"q",

  @"romeo",   @"r",

  @"sierra"@"s",

  @"tango" , @"t",    

  @"uniform", @"u",

  @"victor"@"v",

  @"whiskey"@"w",

  @"x-ray",   @"x",

  @"yankee",   @"y",

  @"zulu",    @"z",  

   

   

   

  @"smily",@"~",

  @"Exclamation",@"!",

  @"Question Mark",@"?",

  @"Hash",@"#",

  @"Percentile",@"%",

  @"Power",@"^",

  @"Ampersand",@"&",

  @"Star",@"*",

  @"Left Curly Bracket",@"(",

  @"Right Curly Bracket",@")",

   

 

     

  nil];    

   

phoneticString = [[NSMutableString alloc]initWithString:@""];

for (int i=0; i<pass.length; i++) {

NSString *first = [[NSString alloc]initWithFormat:@"%c",[pass characterAtIndex:i]];

NSLog(@"%@",first);

NSString *second =[[NSString alloc]initWithFormat:@"%@",[dic valueForKey:first]];

    [phoneticString  appendString:second];

if (i<pass.length-1) {

[phoneticString appendString:@","];

}

}

phoneticsLabel.alpha = 0.9;

NSLog(@"%@",phoneticString);

phoneticsLabel.textColor = [UIColor blueColor];

phoneticsLabel.font = [UIFont fontWithName:@"Helvectia" size:22.0];

phoneticsLabel.text = phoneticString;

}


}






-(IBAction)sendEmail

{

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

picker.mailComposeDelegate = self;

    [picker setSubject:@"Hello iPhone!"];

// Set up recipients

 



(1) Responses to this post

Lakesha May 05 2011 at 11:41:03

This has made my day. I wish all psotngis were this good.


Leave your comment here






User Login




New User Forgot password

Newsletter Subscribe

Advertisement

 
 
 
quick contact