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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

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

Reply
 
LinkBack Thread Tools Display Modes
Old 05-14-2011, 02:53 PM   #1 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,005
Duncan C has a spectacular aura about
Default Sample password generator app - Shared utilities class, data container singleton.

For years now, I've used a simple but effective way to generate passwords that are easy to remember but impossible to crack. I select a pair of random words from a dictionary and combine them, sometimes with a number or symbol separating them.

Earlier this week I found a large (109582 words) word list file on the net, and decided to automate the process.

I wrote a dirt simple Mac application that generates passwords using 2 randomly selected words, separated with a number between 1 and 99. Since the word list is 109582 words, the total number of possible passwords is 109582 * 109582 * 99, or 1,188,813,257,676. That's over 1 TRILLION possible combinations.

I decided to post the app here as a tutorial. It's a Mac app instead of an iOS app, but just about all of the techniques it uses are exactly the same between Mac OS and iOS.

You can download the project from my mobileMe public folder at the following link:

Password generator project

The app demonstrates a number of useful things:
  • Converting a text file into a binary plist.
  • Reading a plist file into an array.
  • Using arc4random to select items from an arbitrary sized array of objects.
  • Using a data container singleton to share data between objects in a project
  • Using a shared utilities (singleton) class to collect common utilities functions. The utilities class includes both class methods (which you can call without having to create an instance of the utilities class) and instance methods.

Running the project requires a word list to work. I wrote it to use a word list file that I found on the web at SIL International. Click that link to download the file..

The terms of use say that you are free to use the file for non-commercial use, but may not republish it without written permission. Thus, you'll need to download the file yourself and drag it to your documents folder before running the program for the first time.

The project is written with an "if (TRUE)" statement that runs a one time setup method that converts the text file into a binary plist. The program expects the source file to be named wordsEn.txt, and saved in the documents directory for the current user on your Mac.

Once you run the program once, it puts up an alert telling you that the plist file has been created. You will then need to drag the plist file into your project's "supporting files" group and click the "copy items into destination group's folder (if needed)" checkbox in the dialog that XCode displays. This will cause XCode to include the plist file in your app bundle.

Once you've copied over the plist file into your project, go to the app delegate and search for "if (TRUE)". Change that line to "if (FALSE)" and the program will no longer create the word list plist file, but will instead try to open the plist file from the bundle at startup.

The program converts the word list into a BINARY plist because binary plists are MUCH faster and MUCH smaller than XML plists. That's an important point for iOS apps, since iOS devices are both slower than Macs and very memory/disk starved. Take a look at the code that saves and loads the plist file. It uses class methods from the NSPropertyListSerialization class instead of the normal NSArray writeToFile:atomically and arrayWithContentsOfFile methods.

The program uses a data container singleton class so it can share data between it's different objects. This is more as a tutorial than anything, since this app really only has an app delegate, and that's about it. The data container singleton class is called DataContainerSingleton. It has a class method theDataContainerSingleton that lets you get to the data container object from any object in your app, using code like this:

Code:
[DataContainerSingleton theDataContainerSingleton].someProperty
If you want to make some value visible from your entire application, simply add a property to the data container singleton object, and read/write to the property using the above syntax. That's all there is to it.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 05-14-2011 at 02:55 PM.
Duncan C is offline   Reply With Quote
Old 06-01-2011, 02:52 PM   #2 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 5
Claire47 is on a distinguished road
Default

I have tried your password generator app and really like it. It has some cool features, thanks.
Claire47 is offline   Reply With Quote
Old 06-06-2011, 11:56 PM   #3 (permalink)
Scan Me !
 
MozyMac's Avatar
 
Join Date: Nov 2009
Posts: 608
MozyMac is on a distinguished road
Send a message via AIM to MozyMac Send a message via MSN to MozyMac Send a message via Yahoo to MozyMac
Default

Thanks for sharing i was looking for something similar.
MozyMac is offline   Reply With Quote
Reply

Bookmarks

Tags
arc4random, data container, passwords generator, singleton, text parsing

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 477
14 members and 463 guests
alexeir, David-T, Dj_kades, foslock, iAppDeveloper, jeroenkeij, LunarMoon, Mijator, Pauluz85, pipposanta, QuantumDoja, robsmy, sacha1996, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,129
Posts: 402,928
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

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