From the course: Advanced iOS Development: Keychain Access

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Add user authentication

Solution: Add user authentication - iOS Tutorial

From the course: Advanced iOS Development: Keychain Access

Start my 1-month free trial

Solution: Add user authentication

(upbeat music) - [Instructor] Okay, so let's go over this challenge of adding user authentication. So the first thing we want to do is fetch the password for this username. So after line 65, I'm going to add a couple of blank lines and I'm going to optionally bind the password fetched from the keychain. So I'll say if let pwSaved for the saved password. And I'll call the secure manager retrievePassword and pass in UN for the unwrapped username. So if we got a password, we want to compare it against the password they typed in. We also unwrap that to pw. So I'll say if pwSaved is not equal to pw then we're basically done. They entered their password wrong and we're going to call completion nil. So that means they shouldn't get stored, they shouldn't be set as logged in, and we're not going to pass back a user login instance. Otherwise, if we didn't get a password, we want to store the user and we can do that here. So…

Contents