UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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 Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.