Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <UIKit/UIKit.h>
- #import <Foundation/Foundation.h>
- @interface MainView : UIView {
- IBOutlet UITextField *passwordLength;
- IBOutlet UISwitch *includeLowerCase;
- IBOutlet UISwitch *includeNumbers;
- IBOutlet UISwitch *includePunctuation;
- IBOutlet UISwitch *includeUpperCase;
- IBOutlet UISwitch *showPhonetics;
- IBOutlet UITextField *password;
- IBOutlet UITextView *phoneticPassword;
- }
- @property (nonatomic, retain) UITextView *phoneticPassword;
- @property (nonatomic, retain) UITextField *passwordLength;
- - (IBAction)setPasssword;
- @end
- #import "MainView.h"
- #define RANDOM_SEED() srandom(time(NULL))
- #define RANDOM_INT(__MIN__, __MAX__) ((__MIN__) + random() % ((__MAX__+1) - (__MIN__)))
- @implementation MainView
- @synthesize phoneticPassword; //Şifrelerin baş harflarinden oluşan hatırlatıcı ipuçları
- @synthesize passwordLength; //Şifre uzunluğumuz.
- - (id)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- }
- return self;
- }
- - (IBAction)setPasssword {
- [UIView beginAnimations:nil context:NULL];
- [UIView setAnimationDuration:1];
- [password setAlpha:0.0];
- [phoneticPassword setAlpha:0.0];
- [UIView commitAnimations];
- [UIView beginAnimations:nil context:NULL];
- [UIView setAnimationDuration:1];
- [password setAlpha:0.85];
- if(showPhonetics.on) {[phoneticPassword setAlpha:0.85];}
- [UIView commitAnimations];
- NSArray *keys = [NSArray arrayWithObjects:
- @"a", @"b", @"c", @"d", @"e",
- @"f", @"g", @"h", @"i", @"j",
- @"k", @"l", @"m", @"n", @"o",
- @"p", @"q", @"r", @"s", @"t",
- @"u", @"v", @"w", @"x", @"y", @"z",
- @"A", @"B", @"C", @"D", @"E",
- @"F", @"G", @"H", @"I", @"J",
- @"K", @"L", @"M", @"N", @"O",
- @"P", @"Q", @"R", @"S", @"T",
- @"U", @"V", @"W", @"X", @"Y", @"Z",
- @"0", @"1", @"2", @"3", @"4",
- @"5", @"6", @"7", @"8", @"9",
- @"~", @"!", @"?", @"#", @"%",
- @"^", @"&", @"*", @"(", @")",
- nil];
- NSArray *objects = [NSArray arrayWithObjects:
- @"ahmet", @"bilkent", @"can", @"delta", @"ekinoks",
- @"fırat", @"gaziantep", @"hakkı", @"ibrahim", @"jeep",
- @"kerem", @"lale", @"mesut", @"nergiz", @"ortaç",
- @"pehlivanoglu", @"queen", @"ramazan", @"serdar", @"taso",
- @"universite", @"vector", @"watson", @"xenon", @"yeşilmen", @"zirve",
- @"AHMET", @"BİLKENT", @"CAN", @"DELTA", @"EKİNOKS",
- @"FIRAT", @"GAZİANTEP", @"HAKKI", @"ISPARTA", @"JEEP",
- @"KAHRAMANMARAŞ", @"LALE", @"MESUT", @"NERGİZ", @"ORTAÇ",
- @"PEHLİVANOGLU", @"QUEEN", @"RAMAZAN", @"SERDAR", @"TASO",
- @"UNİVERSİTE", @"VECTOR", @"WATSON", @"XENON", @"YEŞİLMEN", @"ZİRVE",
- @"Sıfır", @"Bir", @"İki", @"Üç", @"Dört",
- @"Beş", @"Altı", @"Yedi", @"Sekiz", @"Dokuz",
- @"tilde", @"Ünlem", @"Soru İşareti", @"Sayı İşareti", @"Yüzde İşareti",
- @"Üs İşareti", @"Ampersand", @"Yıldız", @"Sol Parantez", @"Sag Parantez",
- nil];
- NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
- NSInteger iPassswordLength = [passwordLength.text intValue];
- BOOL bShowPhonetics = showPhonetics.on;
- BOOL bIncludeLowerCase = includeLowerCase.on;
- BOOL bIncludeUpperCase = includeUpperCase.on;
- BOOL bIncludeNumbers = includeNumbers.on;
- BOOL bIncludePunctuation = includePunctuation.on;
- NSString* passwordText = @"";
- NSString* phoneticText = @"";
- NSString* lowercaseChars = @"abcdefghijklmnopqrstuvwxyz";
- NSString* uppercaseChars = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- NSString* numbersChars = @"0123456789";
- NSString* punctuationChars = @"~!?#%^&*()";
- RANDOM_SEED();
- if(!bIncludeLowerCase && !bIncludeUpperCase && !bIncludeNumbers && !bIncludePunctuation)
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"PasswordGen" message:@"No password character set selected."
- delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
- [alert show];
- [alert release];
- return;
- }
- NSString* passwordChars = @"";
- if(bIncludeLowerCase)
- passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, lowercaseChars];
- if(bIncludeUpperCase)
- passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, uppercaseChars];
- if(bIncludeNumbers)
- passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, numbersChars];
- if(bIncludePunctuation)
- passwordChars = [NSString stringWithFormat:@"%@%@", passwordChars, punctuationChars];
- NSLog(@"Ahmet Dogan & Mesut Seker");
- for(NSInteger i=0; i<iPassswordLength; i++) {
- int index = RANDOM_INT(0, [passwordChars length]-1);
- NSRange range = NSMakeRange(index, 1);
- NSString *passwordChar = [passwordChars substringWithRange:range];
- passwordText = [NSString stringWithFormat:@"%@%@", passwordText, passwordChar];
- NSLog(passwordChar); // Oluşturduğumuz şifreleri terminalde teker teker yazdırma.
- if(i>0)
- phoneticText = [NSString stringWithFormat:@"%@, %@", phoneticText, [dictionary valueForKey:passwordChar]];
- else
- phoneticText = [dictionary valueForKey:passwordChar];
- }
- password.text = @"";
- password.text = passwordText;
- phoneticPassword.text = @"";
- if(bShowPhonetics)
- phoneticPassword.text = phoneticText;
- }
- -(IBAction) resignResponder {
- [password resignFirstResponder];
- [passwordLength resignFirstResponder];
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- if (textField == password) {
- [password resignFirstResponder];
- }
- if (textField == passwordLength) {
- [passwordLength resignFirstResponder];
- }
- return YES;
- }
- @end
- #import <UIKit/UIKit.h>
- @interface MainViewController : UIViewController {
- IBOutlet UIButton *createPassword;
- }
- @property (nonatomic, retain) UIButton *createPassword;
- @end
- #import "MainViewController.h"
- #import "MainView.h"
- @implementation MainViewController
- @synthesize createPassword;
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
- }
- return self;
- }
- - (void)dealloc {
- [createPassword release];
- [super dealloc];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement