Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-26-2010, 11:52 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default Hooking up a password

Hey, I have an app that i'm starting with a UIalertview with a textfield.The textfield is going to be where a person puts a password.

I want the password to be pre-set in the app. So its determined by me not the user.Not quite sure how to save it in the app.

also i want to code it so that if a user puts in something different than the pre-set password the app closes out.

any idea?
evfalcon is offline   Reply With Quote
Old 01-26-2010, 12:37 PM   #2 (permalink)
vja
Registered Member
 
Join Date: Jan 2009
Location: Izhevsk, Russia
Age: 27
Posts: 41
Send a message via Skype™ to vja
Default

For storing passwords and other secure info - use KeyChain.
__________________
be patient, my english is not ideal
vja is offline   Reply With Quote
Old 01-28-2010, 03:01 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

you wouldn't happen to know how to code the password though would you? i'm pretty new to this stuff
evfalcon is offline   Reply With Quote
Old 01-28-2010, 04:25 PM   #4 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

Pre-set in the app is a pretty bad idea unless you really know what you are doing, or what you are protecting is not very important. It's pretty easy for someone with a jailbroken phone to look through your app code to find the password if it's stored in text.

ETA: If you post a little more about why you want it to work this way, we could give you some better advice.
JasonR is online now   Reply With Quote
Old 01-28-2010, 07:03 PM   #5 (permalink)
Beast Iphone Developor
 
justill45's Avatar
 
Join Date: Aug 2009
Location: Atlanta, Georgia
Age: 16
Posts: 1,302
Default

Quote:
Originally Posted by JasonR View Post
Pre-set in the app is a pretty bad idea unless you really know what you are doing, or what you are protecting is not very important. It's pretty easy for someone with a jailbroken phone to look through your app code to find the password if it's stored in text.

ETA: If you post a little more about why you want it to work this way, we could give you some better advice.
people who jailbroke their phone can look at your code???
justill45 is offline   Reply With Quote
Old 01-28-2010, 07:26 PM   #6 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

Not the source code, but they can see and patch the binary. And I think it takes more than just jailbreaking, but the way people pirate your program involves dumping the decoded binary that is running in memory.

If you read the tutorials on Pirate protection on this board, you'll see that pirates will often look at the raw code, and patch out parts to skip code. I'm pretty sure they will also be able to see any string constants you declare in your code.
JasonR is online now   Reply With Quote
Old 01-29-2010, 11:50 AM   #7 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

The app is for the highschool yearbook. So hacking the password isn't going to be a big deal, I just want the password so that creepers can't look at it without having the supplied password..not worried about jailbreaks. So now that that is cleared up can you help me with some code? I can send you code sample if you need it. I just need to know how to hook up the password box to the password and such
evfalcon is offline   Reply With Quote
Old 01-29-2010, 04:40 PM   #8 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

All you need is a UITextView with the "secureTextEntry" property. It's a check box in Interface Builder, or a property on the object if you create it in code.

When the user presses the button, the password will be in the .text property. Just compare it to your password, and go from there.
JasonR is online now   Reply With Quote
Old 01-29-2010, 05:17 PM   #9 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

i'm really new at this could you throw me some code..i really appreciate the help
evfalcon is offline   Reply With Quote
Old 01-29-2010, 05:18 PM   #10 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

also, its a UIalert view...are you able to hook up that button?
evfalcon is offline   Reply With Quote
Old 01-29-2010, 05:41 PM   #11 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

- (void)viewDidLoad{



UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Password"
message:@"\n\n\n" // IMPORTANT
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"Enter", nil];


textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];
[textField2 setBackgroundColor:[UIColor whiteColor]];
[textField2 setPlaceholder:@"password"];
[textField2 setSecureTextEntry:YES];
[prompt addSubview:textField2];

// set place
[prompt setTransform:CGAffineTransformMakeTranslation(0.0, 110.0)];
[prompt show];
[prompt release];

// set cursor and show keyboard
[textField2 becomeFirstResponder];


[super viewDidLoad];
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"2009EVFalcon" ofType:@"pdf"];

/*
If we have to take from its operational directory, then the next 4 lines will be used...

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *saveDirectory = [paths objectAtIndex:0];
NSString *saveFileName = @"myPDF.pdf";
NSString *pdfPath = [saveDirectory stringByAppendingPathComponent:saveFileName];
*/
self.pdfUrl = [NSURL fileURLWithPathdfPath];
[webView loadRequest:[NSURLRequest requestWithURLdfUrl]];
}


- (void)dealloc
{
[webView release];
[pdfUrl release];
[super dealloc];
}
@end
evfalcon is offline   Reply With Quote
Old 01-29-2010, 06:01 PM   #12 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

I don't have any code to help, but it looks like all you need to do is change the code to setup the prompt to use self as a delegate:

Code:
delegate: self
add
Code:
<UIAlertViewDelegate>
to the definition of your view Controller in your .h file,

and create a clickedButtonAtIndex: method that reads the password:

Code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([textField2.text isEqualToString: @"MyPassword"]) {
  // Do something on good password
} else{
  // Do something with bad password
}
I've not compiled this, so there might be minor syntax errors, but I think that's close enough to get you started.
JasonR is online now   Reply With Quote
Old 01-29-2010, 06:03 PM   #13 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

alrighty, thank you, i'll let you know if it works...
evfalcon is offline   Reply With Quote
Old 01-29-2010, 06:42 PM   #14 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

it shows some errors that i'm not sure how to fix...on of them being wrong type arguments to unary minus...this was after i replaced alertView with *prompt..is it me or the code?
evfalcon is offline   Reply With Quote
Old 01-29-2010, 06:49 PM   #15 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

The best thing to do is copy and paste the lines of code, and the error messages. "Unary minus" makes me think you lost a semi-colon or bracket somewhere, so it thinks the "-" at the beginning of a method definition is a math symbol instead.
JasonR is online now   Reply With Quote
Old 01-31-2010, 05:13 PM   #16 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

i was able to get the error messages to go away by adding the end bracket before -(void) i've goofed around with it with no luck..by changing alertView to prompt I get a blank white screen after i enter. I have no clue as to how to make this work..i keep getting the same thing i had before a password box that dosent' work, here is the code i have..

- (void)viewDidLoad{





UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Password"
message:@"\n\n\n" // IMPORTANT
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Enter", nil];


textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];
[textField2 setBackgroundColor:[UIColor whiteColor]];
[textField2 setPlaceholder:@"password"];
[textField2 setSecureTextEntry:YES];
[prompt addSubview:textField2];

// set place
[prompt setTransform:CGAffineTransformMakeTranslation(0.0, 110.0)];
[prompt show];
[prompt release];


// set cursor and show keyboard
[textField2 becomeFirstResponder];
}
- (void)promptUIAlertView *)prompt clickedButtonAtIndexNSInteger)buttonIndex {
if ([textField2.text isEqualToString: @"MyPassword"]) {
// Do something on good password
} else{

}




[super viewDidLoad];
webView.scalesPageToFit=YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"2009EVFalcon" ofType:@"pdf"];

/*
If we have to take from its operational directory, then the next 4 lines will be used...

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *saveDirectory = [paths objectAtIndex:0];
NSString *saveFileName = @"myPDF.pdf";
NSString *pdfPath = [saveDirectory stringByAppendingPathComponent:saveFileName];
*/
self.pdfUrl = [NSURL fileURLWithPathdfPath];
[webView loadRequest:[NSURLRequest requestWithURLdfUrl]];
}


- (void)dealloc
{
[webView release];
[pdfUrl release];
[super dealloc];
}
@end
evfalcon is offline   Reply With Quote
Old 01-31-2010, 06:18 PM   #17 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

The code you posted is scrambled somehow. It looks like you are declaring the clickedButtonAtIndex method in the middle of the viewDidLoad method. It needs to be on its own. I don't see any problems other than that.
JasonR is online now   Reply With Quote
Old 02-01-2010, 10:24 AM   #18 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

I really suck at this lol. I now placed the code under the bracket after the webView load request and i'm still having the same problem...what should I put in the if and else portion of the code..i've put [webView release]; and every release i can think of...i don't know if that what i'm supposed to put in there..The password screen just seems to go away no matter what..right now i can run the app but the password screen lets me enter whether there is a password or not. I really appreciate all your help on this you have helped me bunches already.
evfalcon is offline   Reply With Quote
Old 02-01-2010, 04:59 PM   #19 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

Don't beat yourself up, it sounds like you are just still very new at this. What do you want to happen when the user picks the wrong password? One easy way would be to have the UIAlertView come back up in the "else" part of the code after you've checked for a password. That way the user can't do anything until they get the password right.
JasonR is online now   Reply With Quote
Old 02-02-2010, 10:06 AM   #20 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

alrighty, thank you very much! i was able to get it to work..you can stop replying now! i'm sure you super excited about that lol..thanks for everything
evfalcon is offline   Reply With Quote
Old 02-02-2010, 10:45 AM   #21 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 20
Default

oh and I'm super new at this lol..i started in november and i'm only 18 lol..just thought i'd let ya know
evfalcon is offline   Reply With Quote
Reply

Bookmarks

Tags
app, login, password, uitextfield

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 248
18 members and 230 guests
ADY, Alsahir, beleg_1998, Dani77, diyora, iDifferent, iph_s, JamesCahall, JasonR, mer10, Monstertaco, prchn4christ, Robiwan, Rudy, smithdale87, Speed, spiderguy84, timle8n1
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,755
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:16 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0