views:

141

answers:

3

I need to obtain a Social Security Number in my app, but I don't want the number itself to display in the interface. How do I go about obtaining the input without disclosing the confidential information on the screen?

I have to fill up this application which asking for my social security system number but instead of writing down the numbers it should appear as XXX-XX-XXXX rather than the number itsself because it's confidential.

+8  A: 

Use a secure text field instead of a normal text field (NSSecureTextField).

But I bet interface builder lets you just drag and drop this field.

Update:

And in fact it does:

IB

Felix Kling
please tell me how? what to do?
vernadith
@vernadith: If you don't know how to program in Objective-C or how to use Interface Builder, then you have to learn this first. How did you manage to create your application so far?
Felix Kling
please give me the exact site where i can download this NSSecureTextField that can format my sss number to xxxx
vernadith
@vernadith: Do you develop for iPhone or for Mac?
Felix Kling
vernadith wants it for an iPhone - NSSecureTextField is a Mac OS X only class...
jrtc27
@jrtc27: Well, I don't know. The `iphone` tag was added by someone else and from the original question it is not clear whether it is iPhone or Mac.
Felix Kling
@Felix Kling "What do I use to enter obscured input in an *iPhone* app?"
jrtc27
@jrtc27: This was also edited by another user. Have a look at the revisions: http://stackoverflow.com/posts/3174756/revisions and tell me if you can find which platform he is developing for.
Felix Kling
How could so many people have upvoted this when it's the wrong answer? I'm sure Felix meant well (or answered before the iPhone angle was highlighted), but I just lost a little bit of faith in SO. Vernadith, you should go back and unaccept it.
Joost Schuur
@Joost Schuur: I did mean well :) The original question didn't contain anything that one could even *assume* that it is about iPhone. And I don't know how the others concluded that. I cannot find the slightest hint in the OP's question or comments that it's about iPhone. Until this cannot be ensured, I won't delete my answer. I lost some faith too... but more because some people seem to edit questions how the like it...
Felix Kling
@Felix King: I didn't recognize the extent of editing that had gone on when I posted my comment. Details were 'obscured' (heh) behind the 'add/show more comments' link. No hard feelings. Time to go outside and enjoy some of that good weather it seems...
Joost Schuur
+1  A: 

NSSecureTextField is the equivelant of a password field in the iPhone.

Here's the description from Apple:

A secure text field is a type of text field that hides its text from display or other access via the user interface. It’s suitable for use as a password-entry object, or for any item in which a secure value must be kept. Your code can get the text field’s string value using the standard stringValue method, but users can’t see it or access it. It overrides many aspects of text editing to prevent passing of the object’s value out by mechanisms available to the user (namely, through Cut, Copy, and Paste commands, and the Services facility). This object also overrides the text system’s drawing routine to draw no text at all) . . . Every method in NSSecureTextFieldCell has a cover in NSSecureTextField. (A cover is a method of the same name that calls the original method. http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/TextField/Concepts/AboutSecureTextFields.html#//apple_ref/doc/uid/20000127-BAJCGDIH

Since NSSecureTextField derives from NSTextField, you can find any tutorial on the web on how to use NSTextField -- simply swap NSTextField for NSSecureTextField in the implementation. I bolded the important phrase above (Every method in NSSecureTextFieldCell has a cover in NSSecureTextField). Interact with the NSSecureTextField just as you would a NSTextField object, the interface is exactly the same at the API level.

The NSSecureTextField will show up in an application looking like this:

alt text

When I searched Google for "NSTextField Tutorial", the first result I found was from the following website: http://www.pietrop.com/wordpress/dev-area/tutorials/cocoa-tutorial-nstextfield-nsbutton/#english

In short, you'll end up with a header that looks something like this:

//  Controller.h

#import <Cocoa/Cocoa.h>

@interface Controller : NSObject
{
    //IBOutlets (the inteface's controllers)
    IBOutlet NSSecureTextField *inputText;
    IBOutlet NSTextField *displayedText;
    IBOutlet NSButton *updateButton;
    IBOutlet NSButton *clearButton;
}

/* IBActions (the user interface interactions) */
//Updates the text in the Wrapping Label
- (IBAction)updateText:(id)sender;

//Clears the text in the Wrapping Label and in the TextField
- (IBAction)clearText:(id)sender;

@end
David L Ernstrom
where can i down load it?
vernadith
Isn't all that just for Cocoa under Mac OS? It starts with NS for starters and not UI like the iPhone UIKit elements, and the tutorial you link to makes no reference to the iPhone. I don't understand why you interspersed that iPhone snap shot there. It's misleading.
Joost Schuur
+1  A: 

The standard UITextField for the iPhone has a 'secure' option under Text Input Traits options in Interface Builder. Try that.

Joost Schuur