GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

Project 28 - Authentication

Forums > 100 Days of Swift

Hi Everyone,

I'm on project28 and wondering if anyone has any thoughts. I'm currently doing the challenges and trying to figure out a way to continue to prompt for password, when they enter it wrong. I thought a While loop would help solve this however i thik the problem with that is that it never paused to wait for a response it just constantly cycles round. As a result the UIAlertController never appears.

Any thoughts.... My snippet is below....

                        var authenticated = false

                        while !authenticated {
                            let ac = UIAlertController(title: "Authentication Failed", message: "You could not be identified; please enter Password", preferredStyle: .alert)
                            ac.addTextField()
                            ac.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in
                                guard let input = ac.textFields?[0].text else {return}
                                if input == KeychainWrapper.standard.string(forKey: "Password") {
                                    self?.unlockSecretMessage()
                                    authenticated = true
                                }
                            }))
                            self?.present(ac, animated: true)
                        }

Cheers,

Si

3      

Hello,

I used var timesTried = Int() to track how many times a face/fingerprint authentication has been used. When it's wrong for the third time in a row, then it's the time to display the "Enter the password" alert controller. Once the correct password is entered, you can reset the mentioned property: timesTried = 0.

3      

Hacking with Swift is sponsored by Alex.

SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!

Try for free!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.