Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Updated Sample password generator app - Shared utilities class, data container singleton.

Duncan CDuncan C Posts: 9,116Tutorial Authors, Registered Users @ @ @ @ @ @ @
edited May 2014 in iPhone SDK Tutorials
This is a very old tutorial.

I have recently moved the demo project from the now-defunct MobileMe to github, and updated it to include both a Mac and iOS targets.

For years now, I've used a simple but effective way to generate passwords that are easy to remember but nearly 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 I found a large (109582 words) word list file on the net, and decided to automate the process.

The word list is free for personal use, but not for redistribution. Thus if you want to use that large word list you'll need to download it and install it in the project yourself.

Instead, I've found a smaller word list (75,288 words, after removing non-standard plurals) that IS licensed for redistribution. The new version of the project has this new, smaller word list built into it. The copyright for the new word list requires that you distribute the copyright notices along with the list, so I added a copyright notice to the app targets.

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.

With the smaller word list of 75,288 words, that's still 75,288*c75,288*100, or 566,828,294,400 words. Ok, it's only 5.66 billion possible combinations.

I decided to post the app here as a tutorial. The new version of the project builds both Mac and iOS versions of the app.

You can download the project from my github at the following link:

Password generator project on github

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_uniform 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.
  • Building both Mac and iOS applications from the same project, using shared source code.

The current version includes the shorter word list that is licensed for redistribution. If you instead want to use the longer, 109,582 word list, you can download it 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.

To replace the words list, download the words list file from the link above, drag it into the project, and make sure it is set to be included in the current target. Then delete the included "wordlist.plist" file from the project and run the program. When it fails to find the "wordlist.plist" file, it will generate the plist from the text file, and display a log message telling you where to find the plist file.

You will then need to copy the newly created plist file into the project, and make sure it's "target membership" checkbox is checked for both the iOS and Mac OS targets. You should also un-check the target membership checkbox for the text version of the file once you have generated the plist, since the text version is only needed to create the plist.

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:
[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.

I've been working on a more flexible version of the password generator that lets you mix and match lower-case words, capitalized words, and random numbers/letters/symobols, so you can easily create passwords that meet the requirements of different online logins. I will likely put that improved version up on the app store for a nominal fee, but feel free to use the version in this tutorial as-is, or modify it to meet your needs.
Post edited by Duncan C on
Duncan C

Animated GIF created with Face Dancer, available for free in the app store.

I'm available for one-on-one help at CodeMentor


  • Claire47Claire47 Posts: 5New Users
    edited June 2011
    I have tried your password generator app and really like it. It has some cool features, thanks.
  • MozyMacMozyMac Posts: 609Registered Users
    edited June 2011
    Thanks for sharing i was looking for something similar.
    <div align="center"><a href=""; target="_blank">Free Mac Video Tutorials and Online Help</a></div><div align="center"><a href=""; target="_blank">Steve Job's Most Famous Quotes</a> | Steve Jobs 1955-2011, RIP<br
  • Duncan CDuncan C Posts: 9,116Tutorial Authors, Registered Users @ @ @ @ @ @ @
    Note that the link to the project in this tutorial has been dead since Apple canceled MobileMe. I have posted an improved version of the project to github, and updated the description above to reflect the changes.
    Duncan C

    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
Sign In or Register to comment.