William Lombard
William Lombard

Reputation: 347

Possible to programmatically tap textfields and paste username/passwords? Login not saved in Keychain

I am trying to help my boss and co-workers out with an iOS 12 Swift App to help us all better manage inventory when out on the shop floor.

The all works by taking advantage of the barcode/QR-code reading technology that comes bundled with iOS 12.

The webpage used to log into the inventory service uses plain-old http technology and so the iOS (appears) not to be offering me a means of letting me save/retrieve the password to/from the Keychain. I CAN however save the login information when I access the website via my Mac. I have verified that the login information been saved on the Mac's keychain (which is shared with the iPhone via iCloud).

The webpage warns that the password (on either platform) will be sent unencrypted.

I have adapted some of the code already at https://www.appcoda.com/barcode-reader-swift/.

I don't have a full Apple developer account, so at present this is not a production app.

The main difference between the code supplied by www.appcoda.com/barcode-reader-swift and mine nearly all lies in the 'QRSwiftController.swift' file's func launchApp function. Slight modifications to help improve readability and usability. A Safari View Controller is used make everything more cohesive inside of one app etc.

 func launchApp(decoded_barcode: String) {

    if presentedViewController != nil {
        return
    }

    AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

    let result = decoded_barcode.replacingOccurrences( of:"[^0-9]", with: "", options: .regularExpression)


    let startOfURL: String = "http://xxx.webname.com/deploy/artikel.php?nummer="
    let fullURL = startOfURL + result


    let alertPrompt = UIAlertController(title: "Open App", message: "You're going to open \(fullURL)", preferredStyle: .actionSheet)
    let confirmAction = UIAlertAction(title: "Confirm", style: UIAlertActionStyle.default, handler: { (action) -> Void in

        if let url = URL(string: fullURL){
            let safariVC = SFSafariViewController(url: url)
            self.present(safariVC, animated: true, completion: nil)

        }

    })

    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil)

    alertPrompt.addAction(confirmAction)
    alertPrompt.addAction(cancelAction)

    present(alertPrompt, animated: true, completion: nil)

}

Even when I visit the inventory management website via normal Safari on my iPhone I am prompted for a username/password every time.

Login

Alt URL for login screen https://i.sstatic.net/d2XFO.jpg

Is there any way I possibly circumvent this problem by automating the tapping of the text fields for the username/password (following by pasting the info) and then tapping 'Log in'??

I've looked already for solutions on Stackoverflow but they seem overwhelmingly complicated and/or no longer valid for Swift 4.

Thanks!

Assume generic username and passwords such as 'user' and 'password'.

Upvotes: 1

Views: 319

Answers (1)

William Lombard
William Lombard

Reputation: 347

In the end (as a workaround) I just got Google Chrome (on iOS) to do all the donkey-work (it appears willing to save the password for this website for future retrieval).

if URL(string: fullURL) != nil {
    //let safariVC = SFSafariViewController(url: url)
    //self.present(safariVC, animated: true, completion: nil)
UIApplication.shared.openURL(NSURL(string: fullURL)! as URL) 
}

Upvotes: 0

Related Questions