Password Generator (iOS)
Learning Objectives
- Develop familiarity with essential iOS concepts
- Develop familiarity with Xcode features: integrated documentation, debugger.
- Become more proficient in Swift
- Practice scene transitions with Segues
- Practice using view controller lifecycle functions
- Practice implementing the delegation pattern
Please work in pairs on this homework assignment. I will assume you will self-pair, but if you cannot find somebody to pair with, let me know. Put the name of each student in the header of each Swift source file in the project.
TIP
We will be using GitHub Classrom to manage homework submissions from now on. That won't change a whole lot in terms of how you use Git, it only affects how you will initially create your repo. Instead of creating the repo from scratch under your GitHub account, you will follow the GitHub classroom assignment link to create the repo for your solution.
Part A: Password Generator App
You are to create a very simple password generator app. The main screen of your app shows the generated password using a Label, a button to regenerate the password, and another button to clear the Label
- Use a default password length of your choice
- As a start, use a combination of uppercase and lowercase characters to generate random passwords
You only need to support the iPhone 13 device (not iPad) and portrait screen orientation. These settings can be found under the "Deployment Info" of your project configuration page. Don't worry of the precise layout at this point; Xcode may complain with warnings about layout constraints which you can ignore at this stage of your iOS development. However, be sure that the app is fully functional.
![](/cs357/passwd-gen-clear.png)
![](/cs357/passwd-gen-main.png)
- The screen on the left is the initial state of the app or after the CLEAR button is tapped.
- The screen on the right shows a random password after the GENERATE button is tapped. This button regenerates a new password everytime it is tapped.
TIP
Checkpoint: Have the password generation logic and the clear button working. Do a git-commit and git-push before moving on to part B.
Part B: Password Settings Screen
WARNING
In a real production app, the customization options for generating the password will likely be presented on the same (previous) screen. However, just for this exercise we move this feature to a different screen.
Enhance the password generator app with a setting screen to allow the user to customize how the password is generated. The overall idea is to add another button in the main screen that will transition the app to the settings screen. To use this feature, your screens must be embedded within a navigation view controller (UINavigationController
). Begin by embedding the main screen in Part A above into a navigation controller.
You have to create a new view controller to manage the settings screen. To connect the two screens, add another button (SETTINGS
) in the screen of Part A and use a push segue to transition to the settings screen when the SETTINGS
button is pressed.
Include the following widgets in the settings screen:
- A slider to change the password length
- A toggle switch whether special characters are included in the password
- A check box whether numberic characters are included in the password
- A SAVE button to apply the settings and return to the main screen
- A CANCEL button to ignore the settings and return to the main screen.
The widgets in the settings screen should be initialized with the most recent options selected by the user. Your app is not required to retained these values across multiple launches of the app. When the app is relaunched, it is ok to use the default settings initialized in the main password generation view controller.
![](/cs357/passwd-gen-settings.png)
Unlike the buttons in the password generation screen, the two buttons above are Bar Button Item (UIBarButtonItem
). When you drag them to to navigation bar area at the top of the (iPhone) screen, three slots will be highlighted. Place the buttons in the left and right slots.
Convey the new settings from this screen to the main password generation screen via delegation. You may use Prof. Engelsma's video and sample code below as your reference:
Use the following protocol definition (declared in the view controller for Part B):
protocol SettingsViewControllerDelegate {
func settingChanged(passwordLength: Int, useNumeric: Bool, useSpecialChars: Bool)
}
Helpful Hints
You may have to search the iOS documentation/StackOverflow to learn how to implement some of the functionality described in this homework specification. Here are some hints to get you started:
- You will need to add outlets to your
UILabel
s. These labels are what you use to display plain text - You will need to add actions to handle different functionalities of the buttons, sliders, or toggle switches
- A push segue allows your app to transition "forward" in the navigation graph. In order to go "backward" from the current screen to the previous screen you have to dismiss the current screen (programmatically). Hint: the two view controllers are now children of the
UINavigationController
parent. To dismiss the current screen, you have to look for an appropriate method in the parent. Search for relevant information in theUINavigationController
documentation.
Deliverables
Please the following very carefully:
Make sure you have git-pushed all of your code updates to the repo you created via this GitHub Classroom invitation link by the due date.
IMPORTANT
The instructor will grade your homework based on the last commit pushed prior to the due date on the default branch (typically the
main
branch) of your repo. If your solution was developed in a different branch, be sure merge it to the main branch or change your default branch setting on GitHub. I will not browse through multiple branches in your repo.There is nothing to submit via Blackboard
Grading Rubrics
Grading Item | Point |
---|---|
Project setup in GitHub | 3 |
Password Generator using letters only | 3 |
Clear password | 3 |
Setting View Controller | 3 |
Using Push Segue | 3 |
Passing data to Setting View Controller | 4 |
Handling slider input | 3 |
Handling toggle switches | 4 |
Handling Save/Cancel bar buttons | 4 |
Passing updated settings to main view controller | 4 |
Using special characters in password generation | 2 |
Using numeric characters in password generation | 2 |