BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

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

1      

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.

1      

Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.